Skip to main content
Associate
September 16, 2026
Question

Random SPI communication timeout with STM32H7 when reading sensor data continuously

  • September 16, 2026
  • 11 replies
  • 104 views

I am working on an STM32H7-based project where I continuously poll sensor data over SPI in DMA mode. Everything works as expected for the first few hours, but occasionally the SPI bus freezes and triggers a timeout error (HAL_SPI_ERROR_TIMEOUT).

Resetting the SPI peripheral manually recovers the communication, but I want to identify the root cause instead of using a soft-reset workaround.

Has anyone encountered similar bus lockup issues with STM32H7 SPI DMA implementation? Any tips on proper flag clearing or clearing the FIFO buffer safely would be greatly appreciated!

11 replies

Andrew Neil
Super User
September 16, 2026

Have you:

  1. Checked your I2C lines with an oscilloscope to confirm that they are clean, have good edges, correct levels, etc?
  2. Used an analyser to capture comms; check timing; see what happens at the point the software errors?
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
September 16, 2026

Thanks for the suggestions

To clarify, I'm actually using SPI not I2C but I did hook up a logic analyzer to capture the lines during the failure. The CLK, MOSI and CS signals look clean with sharp edges and there are no obvious signal integrity issues or ringing on the scope.

Ryan Miles
Andrew Neil
Super User
September 16, 2026

To clarify, I'm actually using SPI not I2C 

Sorry - my typo!

 

 I did hook up a logic analyzer ... signals look clean with sharp edges

A logic analyser will always show clean traces with sharp edges - you need to check these things on the oscilloscope.

This is where a logic analyser can mislead if the actual signals are not clean with sharp edges.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
September 17, 2026

Look in the library code what can cause HAL_SPI_ERROR_TIMEOUT. For example, can it be because of delayed interrupt handling?

 

Visitor II
September 17, 2026

I’d check the DMA and SPI status flags when the timeout occurs, especially the FIFO and overrun conditions. Logging the SPI registers before resetting the peripheral may help identify whether the issue is caused by a stuck flag, DMA state, or the sensor holding the bus.

David Littell
Senior II
September 17, 2026

“sensor holding the bus”: How would this happen when using SPI?

It’s unfortunate the OP hasn’t come back with anything beyond the (very thin) initial complaint.  Much more detail is needed on his implementation to effectively prosecute a problem like this.

(Kinda learning to never trust/bother with these first-day-joined-post-problems-like-this.  Andrew has sooo much more patience than I!)

mƎALLEm
ST Technical Moderator
September 18, 2026

(Kinda learning to never trust/bother with these first-day-joined-post-problems-like-this.  Andrew has sooo much more patience than I!)

Seems to be a spammer. It will be reported!

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Associate
September 18, 2026

This is a genuine issue not spam. I agree that my original post needed more technical details. I will capture the SPI and DMA registers when the timeout happens again and update the post.
Thanks to everyone who provided helpful debugging suggestions.

Ryan Miles
David Littell
Senior II
September 18, 2026

I’d suggest you should post a detailed description of what you’ve actually implemented (that itself may highlight an obvious oversight/problem) before just blowing in registers and expecting us to somehow divine a solution.