2021-07-03 09:04 PM
I have a code regarding the SPI interrupt, where my STM32F302R8 nucleo as a master while my arduino board as a slave. In this program, I use PB6(stm32) to pin D8(arduino) as my interrupt pin where the interrupt triggers when D8 goes to LOW.
How my program work is:
I will enters a message in the arduino Serial monitor.
After the message is entered, the arduino will make D8 goes LOW to trigger the PB6(stm32) interrupt at EXTI9_5_IRQHandler.
After interrupt is triggered, the program will execute the SPI_SendDataIT(&SPI2handle,&dummy,1) to fetch the data from slave.
Then, (SPI_ReceiveDataIT(&SPI2handle,&ReadByte,1) will execute.
during this, whenever one byte of data available in the master, the RXNE interrupt will trigger. So, SPI2_IRQHandler function will execute.
So, the problem is, whenever I enters the data inside the arduino serial monitor, it stucks at the SPI_SlaveTransmit function in the while(!(SPSR & (1<<SPIF)));
where the function is:
void SPI_SlaveTransmit(uint8_t data)
{
SPDR = data;
while(!(SPSR & (1<<SPIF)));
Serial.println("transmission complete");
}
meaning the data transfer is not successful. So, I do not know how to troubleshoot this. How do we troubleshoot using debugger especially using SPI interrupt?
Here is my main code:
Before this, during normal SPI transaction, every data that I need to send, I need to read it. But, in this program Im not sure how I am going to do it. There is a yellow line that I highlighted in the program.
Here is my SPI send data interrupt code:
Here is my SPI Receive data interrupt code:
Here is my code for SPI IRQHandling:
Inside the SPI IRQhandling, there is 2 helper functions that will store the data:
spi_txe_interrupt_handle:
spi_rxne_interrupt_handle
2021-07-04 06:39 AM
> while(!(SPSR & (1<<SPIF)));
You want (SPIx->SR & SPIF) instead. This error is pervasive in your code.
Posting code instead of pictures of code is much better.