Main Site Documentation

Variable length SPI reading


#1

I am using a sensor that has SPI interface. The sensor is such that you send several bytes of commands and then continuously send 0xFF until it responds with some byte. Then you need to continue sending 0xFF to read the data it sends back.
The thing is, if I call SPI.WriteRead to send the command, then follow with more SPI.WriteRead, the SCL stops clocking between the calls and the sensor resets to command wait mode.
Is there a way to accomplish this? Or is this something I need to drop down to RLP to handle rather than from .Net MF?

Thanks

Hiroo


#2

Do you have datasheet for your sensor to take a look at?


#3

Sure. It’s this.
http://www.yeitechnology.com/sites/default/files/YEI_3-Space_Sensor_Users_Manual_Embedded_2.0_r10_21Jun2013.pdf

I have a work-around by using UART but I would like to use the UART for another sensor.

Hiroo


#4

Are you controlling the /SS input yourself from a GPIO port?

This has to be held LOW for the entire duration of the data sending and receiving. Raising this will most likely reset the internal state.

The standard way the SPI works is to lower and raise the CHIPSELECT for each call to SPIWriteRead. Try setting this to an unused IO PIN and then control the CS yourself.


#5

Oh, good point. I need to blue-wire something and see if that works. It may be after the weekend when I can report back the findings.

Thank you for the suggestion.

Hiroo


#6

Dave,
You were right on the money. Manually pulling the /SS down and holding it did the trick. It seems that SCL does not really matter. I am getting a good data out.

Thanks for the help.

Hiroo


#7

Glad to help and hear that you got it working.

Sometimes it just needs a second eye on the problem.