2022-12-29 05:06 AM
SPI receive funtion not working correctly. Only one time is working, where is my mistake ?
thanks
void SPITransReceive(SPI_TypeDef* SPIx,uint8_t data,uint8_t *pbuff,uint8_t dataSize){
while(dataSize > 0){
while((SPIx->SR & SPI_I2S_FLAG_TXE) == RESET) {} ;
//SPI_SendData8(SPIx,data);
//SPIx->DR = data ;
*(__IO uint8_t *)(&SPIx->DR) = data;//16 bit type cast ;
while((SPIx->SR & SPI_I2S_FLAG_RXNE) == RESET) {} ;
SPI_I2S_ClearFlag(SPIx,SPI_I2S_FLAG_RXNE);
*pbuff = *(__IO uint8_t *)(&SPIx->DR);
++pbuff ;
--dataSize ;
}
}
2022-12-29 05:56 PM
Have you tried 4 wire bidir mode with mosi pin unassigned (spi signal staying withing the chip)? Also, usually, end of communication should only rely on rxne flag. Writing to DR generates the number of sck bit clocks defined in spi config registers.
2022-12-29 10:27 PM
Which STM32?
> Only one time is working
How do you know? How do you observe it?
JW
2022-12-29 11:04 PM
Firstly I read device id correctly with spi than i read status register, device send status info (0x02)
but receive function turn 0x00 or 0xff
2022-12-29 11:38 PM
You need to write dummy bytr to.the DR to generate the sck clock pulses, then wait for RXNE to read.
2022-12-29 11:54 PM
I did but not working correctly
2022-12-30 01:28 AM