cancel
Showing results for 
Search instead for 
Did you mean: 

SPI INTERRUPT PROBLEM

WM_IR
Senior

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:

0693W00000BckSGQAZ.png0693W00000BckSLQAZ.png0693W00000BckSQQAZ.pngBefore 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:

0693W00000BckSpQAJ.pngHere is my SPI Receive data interrupt code:

0693W00000BckSuQAJ.pngHere is my code for SPI IRQHandling:

0693W00000BckSzQAJ.pngInside the SPI IRQhandling, there is 2 helper functions that will store the data:

spi_txe_interrupt_handle:

0693W00000BckT4QAJ.png 

spi_rxne_interrupt_handle

0693W00000BckT9QAJ.png

1 REPLY 1
TDK
Guru

> 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.

If you feel a post has answered your question, please click "Accept as Solution".