cancel
Showing results for 
Search instead for 
Did you mean: 

SPI_I2S_GetFlagStatus()-call alters SPIn->SR

bernhard
Associate II
Posted on November 28, 2013 at 14:25

Hey everybody,

I'm experiencing unexpected behaviour here:

1. Debug point before entering GetFlagStatus(): SPI2-> SR = 3

2. while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) {}

3. Debug point in GetFlagStatus(): SPI2->SR = 2

How can that be? No interrupts are called, as far as I can tell.

Thanks in advance

Edit:

I also tried

while((SPI2->SR & SPI_I2S_FLAG_RXNE) == RESET) {}

But even when a debug point is set at that very line, than  SPI2->SR = 3, when I press F11 nothing happens, when I press F10 the debugger stays in the while loop with SPI2->SR somehow changed to 2. I dont get it...

I also tried

(SPI->SR = 2)

SPI_I2S_SendData(SPI2, byte);

(SPI->SR = 3)

int i = 1;

(SPI->SR = 2)

#rxne #stm32 #spi #spi_i2s_flag_
3 REPLIES 3
Posted on November 28, 2013 at 14:47

Clearing of the RXNE bit is performed by reading the SPI_DR register.

It's either a running DMA, or your debugger, which reads the SPI_DR register.

JW

bernhard
Associate II
Posted on November 28, 2013 at 14:51

I don't use DMA atm.

The reason was the debugger. If I don't open the peripheral display, everything works fine. Oh looord....

Thank you so much, I'm working on this for 2 days now...

Posted on November 28, 2013 at 15:55

Debuggers interfere with things. People overly assume they are non-invasive, but they are invasive, so things that can't be accessed transparently via scan chains in the background have to fiddled with by pushing in code and executing it. Peeking at peripheral register being particularly invasive, especially when doing so clears pending status. Generally if you want to validate/debug such routines, you need the system to be free standing, and get telemetry out a serial port. At the very least avoid parking peripheral or memory view windows in a way that makes your life difficult.

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