PDA

View Full Version : Using PBPro for SPI Interface



twincitian
- 21st March 2007, 18:26
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.

Normnet
- 21st March 2007, 18:49
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

twincitian
- 21st March 2007, 20:11
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.

Normnet
- 21st March 2007, 23:04
Code for PIC18F452.



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

skimask
- 22nd March 2007, 00:34
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.

GioppY
- 22nd March 2007, 07:57
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