SPI Master RXWNE never sets at high speed
Hi Experts
I have a situation with STMH7 as a master on the SPI3 bus with two slaves (both RM44),
I am using polling on master and chip select lines to select individual slaves.
Problem is at speed greater than 5 Mbps the RXWNE flag never sets and code always stuck at following line of code and never gets inside this if, and RxXferCount never decreases.
if (((hspi->Instance->SR & (SPI_FLAG_RXWNE | SPI_FLAG_FRLVL)) != 0UL) && (initial_RxXferCount > 0UL))But at low speed everything works fine. Could you please throw some light what could be the possible cause of the behavior.
Thanks for your constant support.
Have a lovely day ahead, and please let me know if you need more information.
Following is the complete code for your reference
/* Wait until RXWNE/FRLVL flag is reset */
if (((hspi->Instance->SR & (SPI_FLAG_RXWNE | SPI_FLAG_FRLVL)) != 0UL) && (initial_RxXferCount > 0UL))
{
if ((hspi->Instance->SR & SPI_FLAG_RXWNE) != 0UL)
{
*((uint32_t *)hspi->pRxBuffPtr) = *((__IO uint32_t *)&hspi->Instance->RXDR);
hspi->pRxBuffPtr += sizeof(uint32_t);
hspi->RxXferCount -= (uint16_t)4UL;
initial_RxXferCount = hspi->RxXferCount;
}
else if ((hspi->Instance->SR & SPI_FLAG_FRLVL) > SPI_RX_FIFO_1PACKET)
{
#if defined (__GNUC__)
*((uint16_t *)hspi->pRxBuffPtr) = *prxdr_16bits;
#else
*((uint16_t *)hspi->pRxBuffPtr) = *((__IO uint16_t *)&hspi->Instance->RXDR);
#endif /* __GNUC__ */
hspi->pRxBuffPtr += sizeof(uint16_t);
hspi->RxXferCount -= (uint16_t)2UL;
initial_RxXferCount = hspi->RxXferCount;
}
else
{
*((uint8_t *)hspi->pRxBuffPtr) = *((__IO uint8_t *)&hspi->Instance->RXDR);
hspi->pRxBuffPtr += sizeof(uint8_t);
hspi->RxXferCount--;
initial_RxXferCount = hspi->RxXferCount;
}
}