Skip to main content
superK
Associate II
January 19, 2022
Question

Why does spi communication fall into an infinite loop?

  • January 19, 2022
  • 1 reply
  • 1408 views

After about 14 minutes of normal communication with the chip through spi as the source below, it falls into an infinite loop.

Why do you fall into an infinite loop?

please I'd appreciate it if you let me know.

int spi1_writeread(const unsigned char* txbuff,unsigned char* const rxbuff,unsigned int len)

{

    SPI_HandleTypeDef *hspi = &hspi1;

    HAL_StatusTypeDef temp;

    unsigned char tx[256];

    unsigned char rx[256];

    unsigned int ret = STATUS_OK;

    if(txbuff != NULL)

    {

        (void)memcpy(tx, txbuff, len);

    }

//if ((__HAL_SPI_GET_FLAG(hspi, SPI_FLAG_RXNE)) && (hspi->RxXferCount > 0U))

    while(HAL_SPI_GetState(hspi) == HAL_SPI_STATE_BUSY_TX_RX);

    temp = HAL_SPI_TransmitReceive(hspi,tx,(rxbuff != NULL) ?(uint8_t *)rxbuff : rx ,len,10);

    //printf("rx data : %x , %x\r\n", rxbuff[0],rx[0]);

    if(temp != HAL_OK)

    {

        ret = spi1_open(DEV_SPI_MASTER);

    }

    return ret;

}

This topic has been closed for replies.

1 reply

Ulysses HERNIOSUS
ST Technical Moderator
January 20, 2022

The ticket st25r3916irq-error-problem- from KHyun.1 indicates there is no problem in SPI but on higher layer or wiring.