Hardware SPI with MAX3111E


Closed Thread
Results 1 to 3 of 3
  1. #1
    KHsu's Avatar
    KHsu Guest

    Exclamation Hardware SPI with MAX3111E

    Hi guys,

    Is there a tutorial on hardware SPI? I am trying to establish hardware SPI between a PIC18F66J15 and MAX3111E UART and the problem I am having now is I can't seem to read the data from the UART. I have setup the SSP1CON and SSP1STAT registers on the microcontroller and the UART such that I can send data out to the UART and when the UART gets data I get appropriate interrupt on the microcontroller side. However, when I get an interrupt and go read in the data from the UART the value is always %11111111.

    Any help would be appreciated. Here's a snippet of my code:


    '****Port setup****
    INTCON2.7 = 0 'Disable internal pull ups on port B
    INTCON2.6 = 1 'RQ_RQ from FPGA is active high - rising edge interrupt
    INTCON2.5 = 1 'FPGA_GPINT from FPGA is active high - rising edge interrupt
    INTCON2.4 = 0 'Screw out is falling edge interrupt
    INTCON2.3 = 0 'COMM interrupt is falling edge - active low interrupt.

    '****Here is my SPI Setup****
    SSP1STAT.7 = 0
    SSP1STAT.6 = 1 'sample bit in the middle of data, data tx on rising edge
    PIR1.3 = 0 'Clear the buffer status.
    SSP1CON1 = %00100000 'enable SPI, Master mode, clk=FOSC/4 = 10MHz

    '****Variable****
    SPI_OUT_DAT var WORD SPI_IN_DAT var WORD[4]
    SPICOM_PC_CS VAR PORTE.1

    '****************Read UART***********
    Read_UART:
    'The host will always be sending a four byte comm string out so:
    'First send all zeros to get UART to send out data
    COM_PC_CS = 0
    pauseus 5
    SPI_OUT_DAT.lowbyte = 0
    SPI_OUT_DAT.highbyte = 0
    gosub Send_SPIData
    pauseus 5
    COM_PC_CS = 1
    pauseus 10
    SPI_IN_DAT = SSP1BUF
    pauseus 5
    return
    '
    '**********SPI SEND******************
    Send_SPIData:
    SSP1BUF = SPI_OUT_DAT.HIGHBYTE
    while PIR1.3 = 0 wend
    pauseus 1
    PIR1.3 = 0 'Reset the flag
    SSP1BUF = SPI_OUT_DAT.LOWByte
    while PIR1.3 = 0
    wend
    pauseus 1
    PIR1.3 = 0 'Reset the flag
    return

  2. #2
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default

    First try Shiftout and Shiftin then Hardware SPI.

    Norm

  3. #3
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default

    I haven't studied your code but here is an example:

    The SPI mode allows 8-bits of data to be synchronously
    transmitted and received, simultaneously.

    Shiftin, Shiftout & their MSSP equivalent.
    Code:
    subREAD:
    Low CS
       
    ''''Shiftout sSI,sCLK,msbfirst,[vOP_READ\8,sDONT_CARE\16,vADDRESS_READ\8,sDONT_CARE\8]
    
    
    SSPBUF = vOP_READ ' SEND DATA BYTE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    vDUMMY = SSPBUF
             
    SSPBUF = 0  'DON'T CARE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    vDUMMY = SSPBUF 
            
    SSPBUF = 0  'DON'T CARE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    vDUMMY = SSPBUF
             
    SSPBUF = vADDRESS_READ 
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    vDUMMY = SSPBUF 
            
    SSPBUF = 0  'DON'T CARE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    vDUMMY = SSPBUF         
    
    
    For z = 1 To 200
    
    ''''Shiftin sSO,sCLK,msbpre,[vREAD\8]
    
    SSPBUF = 0
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    vREAD = SSPBUF         
                              
    Next
    
    High CS  
    
    Return
    As a PIC18F452 example see page 130 of 452 data sheet for your SPI configuration of
    SSPSTAT = %01000000
    SSPCON1 = %00100010

    Norm

Similar Threads

  1. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  2. Hardware SPI with AD7680 16 bit ADC
    By Castor in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd June 2008, 09:01
  3. SPI on a pic without hardware SPI?
    By modifyit in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th April 2006, 13:29
  4. how can i use I2C and SPI hardware
    By micro in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd December 2005, 15:33
  5. Hardware SPI
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 7th June 2005, 14:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts