2017-06-08 06:04 AM
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_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE); SPI_I2S_SendData(SPIx, aTxBuffer); Send = false; } // SPI in Receiver mode if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_RXNE) == SET) { // SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, DISABLE); aRxBuffer = SPI_I2S_ReceiveData(SPIx); } }Call
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) {
LSM6DS3_CS_L();
address = address + (1<<7); Send_a_Byte_and_receive(address); WaitSomeTime_GAP_short(); (*data) = Send_a_Byte_and_receive((*data)); WaitSomeTime_GAP_short(); WaitSomeTime_GAP_short(); LSM6DS3_CS_H();WaitSomeTime_GAP_short();
WaitSomeTime_GAP_short();}2017-06-08 11:03 AM
Try
void SPIx_IRQHANDLER(void)
{
// SPI in Transmitter mode
if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_TXE) == SET)
{
SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_TXE, DISABLE);
SPI_I2S_SendData(SPIx, aTxBuffer);
}
// SPI in Receiver mode
if (SPI_I2S_GetITStatus(SPIx, SPI_I2S_IT_RXNE) == SET)
{
// SPI_I2S_ITConfig(SPIx, SPI_I2S_IT_RXNE, DISABLE);
aRxBuffer = SPI_I2S_ReceiveData(SPIx);
Send = false;
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
JW