Skip to main content
Associate II
January 2, 2025
Solved

HAL_SPI_Transmit & HAL_SPI_Receive timing issue

  • January 2, 2025
  • 2 replies
  • 621 views

Hi all,

I am currently working with the STEVAL-PROTEUS1 Board, which incorporates the STM32WB5MMG module and the IIS3DWB high-bandwidth accelerometer sensor, interfaced via SPI_1.

According to the IIS3DWB sensor datasheet, it supports a clock frequency of up to 10MHz and an Output Data Rate (ODR) of 26667Hz (37 microseconds).

My objective is to collect sensor data at an ODR of 26667Hz.

Here are the steps I have taken so far:

  1. Configured SPI_1 to 8MHz.
  2. Configured the sensor to generate an ODR interrupt, which is successfully triggering every 37 microseconds.

The issue arises when collecting data (6 bytes) from the sensor, which is taking 42 microseconds. Ideally, this should not exceed 10 microseconds using HAL functions in blocking mode. I have also tried using non-blocking mode (DMA), but it is taking the same or more time.

Could anyone help me understand if the HAL function is supposed to take 42 microseconds, or if there might be an issue with my implementation?

Note: The M4 core is running at 64MHz and the M0 core at 32MHz.

Thank you in advance for your assistance!

Best answer by TDK

42 microseconds for a blocking HAL call seems reasonable to expect. If you need faster speed, might have to write your own SPI handling. You can also change to the Release build configuration to gain some speed.

Interrupts at more than about 10 kHz start to become more difficult.

Using circular DMA with HAL, and disabling the half-complete interrupt, is probably going to give you the best speed.

2 replies

TDK
TDKBest answer
Super User
January 2, 2025

42 microseconds for a blocking HAL call seems reasonable to expect. If you need faster speed, might have to write your own SPI handling. You can also change to the Release build configuration to gain some speed.

Interrupts at more than about 10 kHz start to become more difficult.

Using circular DMA with HAL, and disabling the half-complete interrupt, is probably going to give you the best speed.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate II
January 7, 2025

Hi @TDK,

I tried using my SPI handler, and it worked perfectly. Thank you for your assistance.