Page 1 of 1

SPI Sent and Receive

Posted: Tue May 10, 2011 1:28 am
by henker
Hello All,

Hopefully someone can help me here.
I'm interfacing a Pressure Sensor Chip to the 18F4865. The interconnection between these two is with the SPI bus.
The way it works is that the PIC has to sent a 11 bit Character which causes the sensor to respond with an 16 bit "answer"
The problem I have is the datasheet of the Pres. sensor is very precise on amount of SCLK pulses between the Dout and Din as well as a 33msec low on the SCLK.
As the clock pulses are controlled by the PIC, how can this be done in flow code.

I have programmed with SPI as to only receive devices (LED displa) or only transmit devices (TC77) but never in/out to one chip.

Any help is appriciated.
Henk

Re: SPI Sent and Receive

Posted: Tue May 10, 2011 10:23 am
by Benj
Hello Henk,

Ok the sensor does sound like it needs some fairly strange timings eg the 33ms low on the clock line.

Your best bet may be to bit bang the SPI connection from within Flowcode. This way you have full control over what is happening.

Here is an exported macro for v4 that does a SPI read and write transaction. You should be able to import it into your program using the Macro -> Import menu.
spi_byte.fcm
(2.78 KiB) Downloaded 1005 times
There are several small delays already in the macro but commented out using a decision. You should be able to manipulate these delays to give you correct SPI timings for your device.

The example connections are:

RB0 - Chip Select - CS
RB1 - Clock - SCK
RB2 - Data Out - SDO - MOSI
RB3 - Data In - SDI - MISO

The connections to your device will have to go like this.

CS - CS
SDO - SDI
SDI - SDO
SCK - SCK

Re: SPI Sent and Receive

Posted: Tue May 10, 2011 11:04 am
by henker
Thanks Ben,

I have FC3, so I can't import the Macro :(
Anyway, I do understand that I would have to create a "home-made" SPI interface.

I will try... Thanks goodness for Oscope.


Henk

Re: SPI Sent and Receive

Posted: Tue May 10, 2011 11:17 am
by henker
Ben,

One more question. Is it possible in Flowcode to Start / stop the Clock on SCLK (C3)?
Is this done with the SPI_Init / SPI_Uninit?

Thanks
Henk

Re: SPI Sent and Receive

Posted: Tue May 10, 2011 12:59 pm
by Benj
Hello Henk,

Here is a v3 version of my bit banged macro. Hopefully this will help to get you started.