cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 spi problem

yashagarwal
Associate
Posted on February 14, 2015 at 14:57

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.

#stm32f4 #discovery #spi #flash
2 REPLIES 2
Posted on February 14, 2015 at 20:36

Are the unexpected bytes a result of sending the command/address to the SPI device?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
yashagarwal
Associate
Posted on February 15, 2015 at 05:12

NO, there is a separate pulse for sending the address. It is only while receiving that I am getting 2 extra bytes of pulses.

From: clive1

Posted: Saturday, February 14, 2015 8:36 PM

Subject: stm32f4 spi problem

Are the unexpected bytes a result of sending the command/address to the SPI device?