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-F280039C: SPI Timeout Not Triggering When Slave is Disconnected on F280039C.

Part Number: LAUNCHXL-F280039C
Other Parts Discussed in Thread: TMS320F280039C

Tool/software:

I'm working on SPI communication between a TMS320F280039C (configured as SPI Master) and a PIC33EP128GP504 (SPI Slave). I'm using a custom SPI driver on the TI side, implementing polling and timeout logic to detect communication failures.

I'm using the following function for SPI transmit/receive with error handling:  

SPI_Status SPI_Transfer_WithStatus(uint8_t txData, uint8_t *rxData, uint16_t timeout_us)
{
    uint16_t timeout = timeout_us;
    SPI_Status status = SPI_OK;

    // Assert CS
    GPIO_writePin(5, 0);
    DEVICE_DELAY_US(2);

    // Wait until TX buffer is not full
   
    while ((HWREGH(mySPI0_BASE + SPI_O_STS) & SPI_STS_BUFFULL_FLAG) != 0U) {
        if (--timeout == 0) {
            GPIO_writePin(5, 1);
            return SPI_ERROR_TIMEOUT;
        }
        DEVICE_DELAY_US(1);
    }

    // Write data
    HWREGH(mySPI0_BASE + SPI_O_TXBUF) = txData;

    // Wait for RX data to be available
    timeout = timeout_us;
   
    while ((HWREGH(mySPI0_BASE + SPI_O_STS) & SPI_STS_INT_FLAG) == 0U) {
        if (--timeout == 0) {
            GPIO_writePin(5, 1);
            return SPI_ERROR_TIMEOUT;
        }
        DEVICE_DELAY_US(1);
    }
    // Read received data
    *rxData = (uint8_t)(HWREGH(mySPI0_BASE + SPI_O_RXBUF) & 0xFF);
    /*
    // Release CS
    GPIO_writePin(5, 1);
    return SPI_OK;
}

However, even when I remove power or disconnect the slave device, the timeout is not triggered. The SPI_STS_INT_FLAG gets set and dummy datas like 0xFF or 0x00 is returned.  

  • Is this expected behavior of the SPI module on F28003x?

  • Is there a way to reliably detect no slave response or timeout ?

  • Is there any recommended strategy for implementing error detection or diagnostics in such SPI master-slave setups?

  • Hi Antony,

    SPI HW cannot detect whether a target is present or not and there is no in-built timeout feature. The controller always generates the clock and POCI will float high/low, so what you are seeing is expected.

    SPI protocol doesn't provide a mechanism for detecting non-response SPI peripheral, since SPI is a simple protocol and there isn't really a must to implement any error checking / bus timeout mechanisms -- usually a simple send/receive data and chip select handling logic (in-built in HW or manual using GPIO) is all that is needed. You could just include while statements to wait for a transfer to complete before reading and returning the data in your transfer function itself, for example. If you really wanted to, you can simplify the above to check for when the INT FLAG and SPI STS is set to 0. Feel free to also see what others have done on E2E. 

    Best Regards,

    Aishwarya

  • Antony,

    Checking in to see if the issue was resolved and/or you had any other questions.

    Best Regards,

    Aishwarya