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
SPI Sent and Receive
- 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
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.
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
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.
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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
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
-
- 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
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
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
- 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
Hello Henk,
Here is a v3 version of my bit banged macro. Hopefully this will help to get you started.
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel