This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-RM42: SPI slave, stuck in the function spiTransmitAndReceiveData

Part Number: LAUNCHXL-RM42

Hi support,

I configured RM42  SPI1 as a SPI slave, and use AM65x MCU as the SPI master. The two boards are connected with SOMI, SIMO, CLK, CS and GND. 

AM65x MCU will loop reading SPI from the RM42 board on start up.

If AM65X board boots up earlier than the RM42 board, everything seems to be fine. But if RM42x board boots earlier, it will be stuck in the function spiTransmitAndReceiveData.

Below is the code RM42 SPI slave:

    // SPI
    spiInit();

    for (;;) {

        // Transmit SPI
        spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, spiTxData, spiRxData);

        // Toggle LED when success
        gioToggleBit(gioPORTA, 2);
    }

When it's stuck, it stays in the endless loop in the function spiTransmitAndReceiveData which is in the spi.c file:

        /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Hardware status bit read check" */
        while((spi->FLG & 0x00000100U) != 0x00000100U)
        {
        } /* Wait */

The value of the spi->FLG is 0x201, sometime it's 0x211.

When this happens, if I recycle the power of the RM42 board, which makes it boot after the AM65x board, it will then work fine. 

So what could be the problem? And how to clear the error and jump out of the endless loop?

  • I have fixed the problem using the following method. 

    I modified the function spiTransmitAndReceiveData, in case there is an error, return from the function:

            while((spi->FLG & 0x00000100U) != 0x00000100U)
            {
                if((spi->FLG & 0x000000FFU) !=0U)
                {
                    return (spi->FLG & 0xFFU);
                }
            } /* Wait */

    Then if there is an error, init the spi again:

            ret = spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, txData, rxData);
            if (ret != 0U)
            {
                spiInit();
            }

  • Hi Kevin,

    I started working on your issue and will provide an update soon.

    --

    Thanks & regards,
    Jagadish.

  • Hi Kevin,

    Actually, i tested with RM57 as slave as i don't had RM42 board. Here i didn't see the issue you mentioned.

    I agreed that it is stuck in the function "spiTransmitAndReceiveData" at line if the slave before restarted 

    But it is not stuck there for ever, once the master sending the data it is parallelly sending data and once required frames are received then it was exit from that function.

    I am attaching my code here, please have a look and modify if any changes required. If still issue doesn't solve then we will do further analysis.

    0535.SPI_SLAVE_POLL_RM57.zip

    8831.SPI_MASTER_TEST_LC4357.zip

    --

    Thanks & regards,
    Jagadish.