cancel
Showing results for 
Search instead for 
Did you mean: 

SPI in Half Duplex Mode for pressure sensor

Martiska.Greg
Associate III
Posted on August 02, 2010 at 21:41

SPI in Half Duplex Mode for pressure sensor

#arm-thumb-stm32-cortex-m3 #spi
6 REPLIES 6
Singh.Harjit
Senior II
Posted on May 17, 2011 at 14:00

Greg, from what I remember, if you turn on receive mode and half duplex, then the STM32 will start doing transfers and you have to enable/disable the SPI port to start and terminate the transfer.

So, my preferred method is to use full duplex mode and I use the receive interrupt (or DMA complete interrupt) to negate the chip select.

This way, I only get a byte back from the slave when I send a byte out. The value of the byte sent is a don't care.

So, in your case, you won't connect the MOSI pin on the STM32 to the pressure sensor (since it probably doesn't have one).

Martiska.Greg
Associate III
Posted on May 17, 2011 at 14:00

Harjit:

Thank you very much for replying. I understand your answer. I was thinking that using full duplex mode with without the MOSI pin connected would work. You are correct in assuming the pressure sensor has no MOSI pin as no input is required. Do you suggest terminated the unused MOSI to ground?

As I understand also, the half duplex receive mode will continually send a clock signal and accept transfers. However, I am not sure how the data is synchronized in this mode. The pressure sensor chip select will start and stop the transfer of actual data to the STM32 but how then are the correct number of bytes transferred to a value? Also, the spi clock is always on creating noise in the circuit.

The full duplex mode without the MOSI will solve all the issues. It just seems like this is not the intended way to use half-duplex devices. But if it works, it works.

Thanks again,

Greg

Singh.Harjit
Senior II
Posted on May 17, 2011 at 14:00

For MOSI, you have a few choices. If you don't need MOSI for another external SPI device, in the port configuration, don't set it to alternate function. Instead, leave it as a GPIO. If you then don't need an output/input, you could then configure it as an output and set the level to low. This way, you don't have any external components and the signal will be at a known static level.

The receiving device will ignore the SPI clock when its chip select is negated. Also, in full duplex mode, I don't think it will generate a continuous clock - I could be wrong about this since it has been a while since I looked at the SPI function.

Regardless, the SPI block samples data using the SPI clock, so when the chip select is asserted, the SPI slave will use the SPI clock to output data which the SPI block in the STM32 will then sample.

Harjit

Martiska.Greg
Associate III
Posted on May 17, 2011 at 14:00

Harjit:

The spi will not generate a clock in full duplex. Only when sending. I have verified this in the past with my scope.

I did not think about using full duplex spi without configuring a MOSI pin. This is an excellent suggestion. I do not need another GPIO pin but I do not like to configure pins that are not used as designed.

I will give your suggestions a try and let you know how they work out.

Thanks again,

Greg

teichtmann
Associate
Posted on July 28, 2011 at 18:30

I had a similar problem with reading 3 bytes from an external ADC.

In the end - thanks to this thread - i switched over to the bidirectional mode without using the MOSI pin. It cost me a lot of time to find out, that the unidirectional mode seems to be useless in this case. As soon as you enable the module, it starts clocking permanently on SCK, but it is impossible to ''sync'' the data bits from the ADC.

But what is the intended use for the unidirectional mode?
John F.
Senior
Posted on July 29, 2011 at 10:34

I'm trying to understand the STM32F103 SPI interface. I have read and re-read RM0008 but that doesn't describe NSS in any way I understand!

Could you describe the SPI mode or register settings you used. For example, the state of SSI, SSM and SSOE. Is the NSS output in hardware or software mode? If (STM32 in master mode) it is asserted automatically in hardware mode can it be de-asserted by software? Is that what Harjit Singh was describing? Any information or diagrams welcomed.

thanks, John F.