2016-02-27 11:04 AM
Hi,
I am pasting a piece of code I used for SPI communication in STM32F4 Discovery board.The code is working, I have no doubts. I faced an issue while in debugger mode. I added a break point at line number //while
(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
Here RXNE is not getting updated and system will not execute the remaining code. The code works as expected when not in debugger mode or if breakpoint is added after line
Can someone please explain me the reason behind this behavior.
I am using A to B connector to connect my Discovery and I am using Keil 4.
Thanks
Abin
uint8_t SPI_read(uint8_t address)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_3);
address = 0x80 | address;
// 0b10 - reading and clearing status
while
(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, address);
while
(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
SPI_I2S_ReceiveData(SPI1);
while
(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, 0x00);
while
(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
GPIO_SetBits(GPIOE, GPIO_Pin_3);
return
SPI_I2S_ReceiveData(SPI1);
}
#spi-stm32f4-discovery-board
2016-02-27 03:25 PM
Ok, the debugger doesn't have some magic access rights, in reading the DR to display it, it will clear the SR/RXNE, just as it would if you read it in your program. I would strongly recommend not using a Peripheral Viewer to watch activity, rather just for configuration.
If you want to ''debug'' SPI or USART functionality you might want to read the SR and display salient details via GPIO pins, SWV or USART2016-02-28 12:15 AM
Thanks again :)