cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767 SPI Bidirectional Receive Mode : More SPI Clocks are output than I expected.

MBaek.1
Associate

Hello,

I have a question about SPI Bidirectional Mode of STM32F767.

(using HAL Driver / DMA / act as SPI Master)

also, SPI Slave Device is TI LM74 temperature sensor.​

(​https://www.ti.com/product/LM74)

SPI Initialize Parameters are below.

hspi4.Instance = SPI4;
  hspi4.Init.Mode = SPI_MODE_MASTER;
  hspi4.Init.Direction = SPI_DIRECTION_1LINE;
  hspi4.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi4.Init.CLKPolarity = SPI_POLARITY_HIGH;
  hspi4.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi4.Init.NSS = SPI_NSS_SOFT;
  hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
  hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi4.Init.CRCPolynomial = 7;
  hspi4.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi4.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

To read 2 BYTES from device,

I call function HAL_SPI_Receive_DMA() in my user code,

of course Size parameter is 2.

When I check the signal waveforms using Oscilloscope,

I expected ​16-bit SPI Clock pulses are output,

but actually there are 24-bit SPI Clock pulses are output.

How can I handle this situation?

Please tell me a solution.

Best Regards,

4 REPLIES 4
MSpot.1
Associate II

Can you post a screenshot of you spi/dma registers.​

When in bidir mode you turn to Rx, SPI starts to churn clocks out autonomously. The trick is in precise timing, forget about Cube/HAL.

JW

You mean that USE Low-Level Programming Method(e.g, Register Access), NOT USE HAL API Function?

If You possible, could you share to me an Example Code(pseudo-code is OK) or Sequence Flow

about SPI Master 1-Line Bidirection Communication?

​Thanks,

Again, the key here is to have precise control over what you do, Cube is not designed for that. You need to stop receiving early during the last received byte, as described in RM (have you read it?).

The L4 Disco contains an MEMS chip which is controlled through bidir SPI, see it's example code in CubeL4. Make sure to disable interrupts when used in real application.

All of this is written under that link I gave above.

JW