SPI Sent and Receive

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
henker
Posts: 45
Joined: Mon Dec 22, 2008 11:22 pm
Location: Prospect, NS, Canada
Has thanked: 7 times
Been thanked: 2 times
Contact:

SPI Sent and Receive

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: SPI Sent and Receive

Post 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 947 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

henker
Posts: 45
Joined: Mon Dec 22, 2008 11:22 pm
Location: Prospect, NS, Canada
Has thanked: 7 times
Been thanked: 2 times
Contact:

Re: SPI Sent and Receive

Post 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

henker
Posts: 45
Joined: Mon Dec 22, 2008 11:22 pm
Location: Prospect, NS, Canada
Has thanked: 7 times
Been thanked: 2 times
Contact:

Re: SPI Sent and Receive

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: SPI Sent and Receive

Post by Benj »

Hello Henk,

Here is a v3 version of my bit banged macro. Hopefully this will help to get you started.
Attachments
SPI_BYTE.fcf
(4.5 KiB) Downloaded 850 times

Post Reply