AnsweredAssumed Answered

STM32F407 SPI Irq handler - timing issue

Question asked by on Jun 8, 2017
Latest reply on Jun 8, 2017 by waclawek.jan

Dear Community,

I want to send and receive SPI data using the SPI-Irq handler of a STM32F407 device. Using a low speed SPI everything worked so far but now I need to speed thinks up and I noticed that receiving works mostly not and I don’t know why. I’ve checked the slave signal (see attached Image: MOSI: blue; MISO:yellow ; CLK:green; CS:pink) to make sure there is data available for receiving and I’ve also checked the MISO pin that indeed receives zero if connected to ground and 1’s if connected to Vdd. Since I have 8 bit and 16bit devices wired together to the same bus I’ve to stick to the 8bit transmission. In this case  I've always receive 255.

I think the problem is a timing issue and I would be glad if some could point me to the right direction.

IRQ Handler


void SPIx_IRQHANDLER(void)

 // SPI in Transmitter mode
  if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_TXE) == SET)
   SPI_I2S_SendData(SPIx, aTxBuffer);
   Send = false; 
   // SPI in Receiver mode
  if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_RXNE) == SET)
      aRxBuffer = SPI_I2S_ReceiveData(SPIx); 


unsigned char Send_a_Byte_and_receive(unsigned char TheByte) {
       Send = true;
       aTxBuffer = TheByte;
        // Enable the Tx and Rx buffer empty interrupt
        SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, ENABLE);
        SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, ENABLE);
       while(Send) {}
       return aRxBuffer; 


void ReadData16LSM6DS3(unsigned char address, unsigned char * data) {

  address = address + (1<<7); 
  (*data) = Send_a_Byte_and_receive((*data));