How to setup the SPI module to send and recieve data

karabo
Posts: 3
Joined: Fri Mar 20, 2009 4:56 pm

How to setup the SPI module to send and recieve data

Postby karabo » Fri Mar 20, 2009 5:20 pm

Hello Mr. Lubin,

We are a team of students at Oakland University, USA and we are currently working on a project that uses dspic (30f4011)controller and we are currently using your dspic toolbox for spi communication. We are communicating to the pressure sensor that has spi interface. We looked through your forum and exmaple and it's useful, however it didn't help us setup the SPI block for receiving data from the pressure sensor to micro and to send data from micro to a transmitter though UART. Could you please give us a direction on how to configure the spi block to send and receive data. I have attached the simulink model that we have so far, but our model is not complete. Your help is appreciated.

Here is a summary of the things that we want to accomplish:
Send 8 bits command to the pressure sensor through the SPI module of the dspic.
Receive the pressure data from the pressure sensor
Send the pressure sensor data to the UART using the dspic

I have attached the simulink block diagram and pressure sensor data sheet
Thank you very much for your help.
Khalid
Attachments
PressureSensor.mdl
(27.67 KiB) Downloaded 166 times
sp12.pdf
(334.91 KiB) Downloaded 203 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: How to setup the SPI module to send and recieve data

Postby LubinKerhuel » Sat Mar 21, 2009 4:31 pm

I had a quick look.

On the model prinple, it is Ok. However, I noticed few possible problems :
- It seems that data length is 8 bits on the with this SP12 Tyre pressure sensor. Thus, SPI Should be configured with 8 bit data length. (except if you use 16 bits length commands)
- Uart : 9% error @115200 : It is too much. I modified it to 38400.

There may still be some errors, try modifying the SPI mode (or check it carefully from the datasheet), try with and without the 'wait' checkbox.

You may try this attached version, using rs232gui from matlab to watch temperature.
I may have exchange LSB with MSB, It will be quick to check...

Lubin
Attachments
shot_20090321163216-031.png
PressureSensor_corr.mdl
(35.58 KiB) Downloaded 160 times

karabo
Posts: 3
Joined: Fri Mar 20, 2009 4:56 pm

Re: How to setup the SPI module to send and recieve data

Postby karabo » Tue Mar 24, 2009 2:30 am

Thank you Lubin for your diagram, it builds and compiles fine, but the chip select doesn't seem to be selected(pulled low) by the pic micro. We are using 10k resistor. Do you know why this is happening?

Thanks
Khalid

karabo
Posts: 3
Joined: Fri Mar 20, 2009 4:56 pm

Re: How to setup the SPI module to send and recieve data

Postby karabo » Tue Mar 24, 2009 3:16 am

I have another question, do we have to use the pin mapping in our simulink model?

thanks
Khalid

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: How to setup the SPI module to send and recieve data

Postby LubinKerhuel » Thu Mar 26, 2009 12:22 am

Hey,

About chip select, are you checking the correct pin. It is B2 on the model presented here. You should try to disconnect the B2 pin from the temperature sensor pin. Check that its value changes with an scope. You may also check that both :
- the dsPIC SPI clock
- the output data (SDO)
are changing with a scope (while not connected to the SPI sensor to possibly electronic design problems like short-circuit).
This is possible because the SPI peripheral do not wait for incomming data. Thus, its output pin (Chip Select, clock and SDO) will change even if no component are connected on the other side. In that way, it is much more easy to debug than I2C...

There is not PIN mapping requirement of dsPIC 30f4011 because there is no PIN mapping mechanisme built-in that chip.

Lubin

EZY
Posts: 1
Joined: Tue Mar 31, 2009 2:48 am

Re: How to setup the SPI module to send and recieve data

Postby EZY » Tue Mar 31, 2009 3:16 am

Hello Lubin:

The SPI block diagram works partially, at least there is a communication established from dsPIC to the pressure sensor (SP12). The only problem I'm running into is sending two consecutive messages at almost the same time. The SP12 pressure/voltage/temp/acceleration sensor works this way. Initial message is sent to request measurement (in this case voltage) of a voltage 0010 0101(MEASURE _B) followed by 0010 1001 (RCBD - read compensated voltage data). These two messages need to be send to the SP12 in one SPI clock cycle (8bit clock) in order for the sensor to recognize the message as a valid request to measurement and read back measured value message. I tried playing with the chip select but that doesn't make a difference since there are two blocks of SPI in the diagram, two 8bit SPI clocks are generated. Is there anyway to send the 148 and 164 from one SPI block, one after the other to the sensor?

Thanks,
-Esayas

PressureSensor_corr_Voltage.mdl
(35.58 KiB) Downloaded 164 times


Return to “dsPIC Peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest