AnsweredAssumed Answered

stm32f4 spi problem

Question asked by agarwal.yash on Feb 14, 2015
Latest reply on Feb 15, 2015 by agarwal.yash
Hi, the code for my interrupt handler is below


void SPI_IRQHandler(SPI_TypeDef * SPIx)
{
     uint8_t SPIn = (SPIx == SPI1) ? 0 : ((SPIx == SPI2) ? 1 : 2);
     if(SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_RXNE) == SET)
     {
          if(_RxCounter[SPIn] < _RxNumData[SPIn])
          {
               if(_RxBuffer[(SPIx == SPI1) ? 0 : ((SPIx == SPI2) ? 1 : 2)])
               {
                    _RxCounter[SPIn]++;
                    _RxBuffer[SPIn][_RxCounter[SPIn] - 1] = SPI_I2S_ReceiveData(SPIx);
                    SPI_RX_UserCallback(SPIx, _RxBuffer[SPIn], &_RxNumData[SPIn]);
               }
               else
                    SPI_I2S_ReceiveData(SPIx);
          }
          else if(_RxCounter[SPIn] == _RxNumData[SPIn])
          {
               if(_RxBuffer[(SPIx == SPI1) ? 0 : ((SPIx == SPI2) ? 1 : 2)])
               {
                    SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE);
                    SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, DISABLE);
                    while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET);
                    spi_ready(SPIx);
                    SPI_RXTC_UserCallback(SPIx, _RxBuffer[SPIn], &_RxNumData[SPIn]);
               }
          }
     }
     if(SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_TXE) == SET)
     {
          if(_TxCounter[SPIn] < _TxNumData[SPIn])
          {
               if(_TxBuffer[(SPIx == SPI1) ? 0 : ((SPIx == SPI2) ? 1 : 2)])
               {
                    _TxCounter[SPIn]++;
                    SPI_I2S_SendData(SPIx, _TxBuffer[SPIn][_TxCounter[SPIn] - 1]);
                    SPI_TX_UserCallback(SPIx, _TxBuffer[SPIn], &_TxNumData[SPIn]);
               }
               else
                    SPI_I2S_SendData(SPIx, (SPIx == SPI1) ? DUMMY1 : ((SPIx == SPI2) ? DUMMY2 : DUMMY3));
          }
          else if(_TxCounter[SPIn] == _TxNumData[SPIn])
          {
               if(_TxBuffer[SPIn])
               {
                    SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE);
                    while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_BSY) == SET);
                    spi_ready(SPIx);
                    SPI_TXTC_UserCallback(SPIx, _TxBuffer[SPIn], &_TxNumData[SPIn]);
               }
          }
     }
}


I am getting 2 extra bytes of clock pulse while receiving data from the flash memory (SPI communication). Why am I getting this problem and How to rectify it ? Any kind of help would be appreciated. Thank You.

Outcomes