cancel
Showing results for 
Search instead for 
Did you mean: 

Why does spi communication fall into an infinite loop?

superK
Associate II

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;

}

1 REPLY 1
Ulysses HERNIOSUS
ST Employee

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