cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411 SPI RXNE bit is automatically clear

Phuc Nguyen
Associate II

I'm very first to embedded programming, i have written a application using SPI protocol to communicate with 2 STM32F411 broads. And I got trouble in slave code, when the data from the master are sent to slave, then slave RXNE bit is set and go to SPI1_IRQHandler but if i go to HAL_SPI_IRQHandler(&hspi1), this bit is automatically clear while DR is still have data ? Do i need to check anything ? Or Can you tell some bugs possibly happen in my application ? Tks you so much .0690X000006DulSQAS.png0690X000006DulNQAS.png

8 REPLIES 8

Don't inspect them in the debugger, it doesn't have magical powers, reading and dumping DR will still clear RXNE in SR.​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

In slave mode use dma.cyclic mode to a tx and rx buffer. Use exti on nss rise edge to process data. This way the race condition and receiving too much data is under hw control.

thanks for your help. Now i dont understand so much about DMA , i think i will explore later.But Do you know anything about which is bug my code got? This bug is really weird for me, the program just jump to another function and SR is changing ?

This bug is really weird for me, the program just jump to another function , why is SR changing. I think there is some factors causing this bug ? If i dont believe with the debugger , which is i should use debug my code?

You need to have your code inspect the value in SR, put it in a RAM variable, and inspect the RAM variable. The Instance pointer points to the peripheral registers directly. Learn to instrument your software so it can report status and flow in real-time without stopping the machine or sticking your fingers in the gears.

Like repeatedly opening an oven to see how hot it is, put a thermometer in the oven, and look through the window at it.

This is a Schrodinger's Cat issue, you are altering the outcome of the experiment by looking in the box.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

WARNING: If you show the SPI DR regiser when debugging, the ST Link will make a read register access to display the content. This may cause some SR flag to clear when breakpoint. This is the classical side effect when debugging...

Normally you have to open a peripheral view, HAL mixes that up by having an Instance pointer, and now the mere decomposition of a structure/variable causes it. And perhaps anything else silently walking the trees.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

So , I have to create a variable containing value in SR , right? Since english is not my native language , i need to reconfirm it for sure . 😂