Skip to main content
Graduate
January 25, 2024
Solved

while (!LL_SPI_IsActiveFlag_RXNE(EVE_SPI)) {} Never Returns

  • January 25, 2024
  • 2 replies
  • 1536 views

I'm trying to use SPI to communicate with a display (BT817) and whenever it tries to send data, the while (!LL_SPI_IsActiveFlag_RXNE(EVE_SPI)) {} never returns.  I've attached my CUBE IDE project.  Could anyone possibly give some guidance?  Am I missing a setting, have the clock misconfigured?  The board has a STM32F030R8Tx.

Kindest regards

    This topic has been closed for replies.
    Best answer by Pavel A.

    Usually LL_SPI_Enable is called after LL_SPI_Init and before the SPI is used to move data.

     

    2 replies

    Super User
    January 25, 2024

     the while (!LL_SPI_IsActiveFlag_RXNE(EVE_SPI)) {} never returns.

    This is because the while loop in C language will loop until the expression becomes false. If it never becomes false, the loop will be endless. What you can do to avoid endless loop:

    1. Add timeout check: while ((condition) && !timeout_expired(...)) {}  or while (condition) { if (timeout_expired(...)) break; }

    2. Add a software or hardware watchdog

     

     

    kumaichiAuthor
    Graduate
    January 25, 2024

    Thanks for the reply and explanation. I actually got it to work, I was missing the call to, LL_SPI_Enable(EVE_SPI).  Which leads me to my next question, in the main.c file, it initializes the SPI via, MX_SPI1_Init() but it won't work until I call the LL_SPI_Enable method.  At which point should I make the call to, LL_SPI_Enable(...)?

    Thanks!

    Pavel A.Answer
    Super User
    January 25, 2024

    Usually LL_SPI_Enable is called after LL_SPI_Init and before the SPI is used to move data.