Using PBPro for SPI Interface


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Posts
    2

    Default Using PBPro for SPI Interface

    Hi.

    I have looked at a number of examples on this site for interfacing to ADCs using Shiftin and Shiftout. Unfortunately they all either write data to OR read data from a device. I could find no example of simultaneously writing and reading a device as is required for the LTC2442(see attachment).

    Am I correct in assuming that the Shiftin and Shiftout commands won't work for this device? That I will need to talk to the device using a brute force approach?

    Thanks.
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default

    Hardware SPI (MSSP) works both send and receive at same time. Much faster than Shiftin and Shiftout too.

    Have example if you are interested.

    Norm

  3. #3
    Join Date
    Mar 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply.

    Amazing how knowing what to look for(hardware SPI MSSP) results in many more search hits.

    I would welcome any and all examples you may have.

    Thanks Much.

  4. #4
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default

    Code for PIC18F452.

    Code:
    subMSSP:  for 32 bits send/receive 4x
    Low CS
    
    SSPBUF = send_byte3 ' SEND DATA BYTE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    receive_byte3 = SSPBUF
    
    SSPBUF = send_byte2 ' SEND DATA BYTE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    receive_byte2 = SSPBUF
    
    SSPBUF = send_byte1 ' SEND DATA BYTE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    receive_byte1 = SSPBUF
    
    SSPBUF = send_byte0 ' SEND DATA BYTE
    While SSPSTAT.0 = 0: Wend ' WHILE TX/RX COMPLETE
    receive_byte0 = SSPBUF
            
    High CS  
    
    Return
    See page 130 of 452 data sheet for your SPI configuration of
    SSPSTAT = %01000000
    SSPCON1 = %00100010

    Norm

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by twincitian View Post
    Hi.

    I have looked at a number of examples on this site for interfacing to ADCs using Shiftin and Shiftout. Unfortunately they all either write data to OR read data from a device. I could find no example of simultaneously writing and reading a device as is required for the LTC2442(see attachment).

    Am I correct in assuming that the Shiftin and Shiftout commands won't work for this device? That I will need to talk to the device using a brute force approach?

    Thanks.
    I just looked at the complete datasheet for the LTC2442, and I think you might be reading the diagram wrong.

    They do show both SDI and SDO on the same diagram, and both doing input and output at the same time, I'm almost positive that the only reason they did this was to make one diagram, instead of making 2.
    In that diagram, if you're doing input to the '2442, ignore the SDO line, and vice-versa for doing output.
    Therefore, shiftin and shiftout may work for this device...provided they can go fast enough for you, which they should do just fine. The book says roughly 50khz at 4mhz oscillator speed, and I can clock mine at about 500khz at a 40mhz clock speed on an 18F4620, so the math does work out.
    Last edited by skimask; - 22nd March 2007 at 00:37.

  6. #6
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    If you need a software spi; try this
    '
    Bcnt var byte
    SD_Tx var byte 'data to send
    SD_Rx var byte 'data received
    '
    Ck_SD var PortA.3 'pin 2
    Miso var PortA.2 'pin 1
    Mosi var PortA.1 'pin 18
    Cs_SD var PortA.0 'pin 17
    '

    '
    Tx_spi:
    Bcnt = 0 'bit counter
    while Bcnt < 8 'invia 8 bit
    Ck_SD = 0 'clock low
    Bcnt = Bcnt + 1
    Mosi = SD_Tx.7 'invia Msb first a SD card
    SD_Tx = SD_Tx << 1 'prepara prossimo bit uscita
    Ck_SD = 1 'clock up
    SD_Rx = SD_Rx << 1 'fa spazio x nuovo bit
    SD_Rx.0 = Miso 'lettura bit da SD card
    wend
    return

    Regards

Similar Threads

  1. LCDOUT w/custom interface?
    By Mike, K8LH in forum PBP Extensions
    Replies: 4
    Last Post: - 3rd March 2015, 03:54
  2. Replies: 33
    Last Post: - 19th March 2010, 03:02
  3. ICD use with MCS Plus, PBPro & PicKit2??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 30th September 2009, 23:06
  4. 'SCI' interface
    By ecua64 in forum Off Topic
    Replies: 0
    Last Post: - 29th September 2005, 16:02
  5. User Configuration Interface in PBP
    By Radiance in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th February 2004, 08:00

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