AnsweredAssumed Answered

Missing data on the SPI bus?

Question asked by fantana.brian on Dec 9, 2011
Latest reply on Dec 12, 2011 by fantana.brian
I have a Max3107 UART hooked up via the SPI1 bus on a STM32F103ZG. Currently, I can configure the UART, write data out and receive it. I'm trying to implement trigger interrupts because the UART has a 128 word FIFO and I need to make sure I don't overfill the FIFO when dumping a bunch of data in, but I seem to have run into a problem. 

In my configuration I enable the interrupt to be thrown once it reaches ~112 words. The RTOS handles the interrupt but when I go to read the UART to see why the interrupt was thrown, I end up reading an empty SPI data register. I have a logic analyzer hooked up to the SPI bus and I can see the read coming from the STM32. The kicker is I can also see the UART sending the response in the same transaction as expected, but when I'm reading the SPI data register it says there is nothing there, even though I wait on the SPI status register's RX flag before a read. It almost seems that the RX flag is set before the data is in the register(is this possible).

I would think the problem lies somewhere in my ISR code, but before the UART trigger IRQ, I properly handle an interrupt from the UART signaling the crystal has settled. When I read the data register for that interrupt, the data I see on the SPI bus with the logic analyzer is the same data I read out of the data register. 

This snippet is how I read the SPI register.

volatile CPU_INT16U read_data = 0;
/* Drop slave select low, send data and wait until its sent */
SPI_I2S_SendData(spi_port, write_byte);
while(SPI_I2S_GetFlagStatus(spi_port, SPI_I2S_FLAG_TXE) == RESET) { }
/* Wait for data to read, read it, then raise the slave select */
while(SPI_I2S_GetFlagStatus(spi_port, SPI_I2S_FLAG_RXNE) == RESET) { }
read_data = SPI_I2S_ReceiveData(spi_port);
return read_data;

I'm curious if anyone else has seen this? Any suggestions or pointers are greatly appreciated. Thanks!