Skip to main content
MBaek.1
Associate
December 15, 2020
Question

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

  • December 15, 2020
  • 4 replies
  • 1159 views

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,

This topic has been closed for replies.

4 replies

MSpot.1
Associate II
December 15, 2020

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

waclawek.jan
Super User
December 15, 2020

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

MBaek.1
MBaek.1Author
Associate
December 16, 2020

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,

waclawek.jan
Super User
December 16, 2020

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