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.

AM2431: Question about the SPI read logic in SDK version 08.05

Part Number: AM2431

Hi, ex
I am looking at the example code from mcspi_performance_8bit_am243x-lp_r5fss0-0_freertos_ti-arm-clang example in latest version of SDK. In the example code, it waits for Tx FIFO to be empty before writing the bytes and similarly it waits for Rx FIFO to be full before reading any bytes out.

My question is, why does it have to wait for tx FIFO to be empty before writing the bytes in? Can it not write a byte as soon as TXS (bit 1 in status register) is 1 indicating the register is empty? Similarly during read can it not just wait for RXS bit to be 1 and read the byte as soon as it shows up? What difference would it make if we do it this way?

Here is the code from the example:

while (transferLengthTx != 0)
{
if (0 != (MCSPI_readChStatusReg(baseAddr, chNum) &
CSL_MCSPI_CH0STAT_TXFFE_MASK))
{
/* Write Effective TX FIFO depth */
if (transferLengthTx >= effTxFifoDepth)
{
transferLengthTx = effTxFifoDepth;
}
/* Write the data in Tx FIFO. */
for (i = 0; i < transferLengthTx; i++)
{
MCSPI_writeTxDataReg(baseAddr, (uint8_t) (*txBuff++), chNum);
}
numWordsWritten += transferLengthTx;
transferLengthTx = length - numWordsWritten;
}
if (0 != (MCSPI_readChStatusReg(baseAddr, chNum) &
CSL_MCSPI_CH0STAT_RXFFF_MASK))
{
/* Write Effective TX FIFO depth */
if (transferLengthRx >= effTxFifoDepth)
{
transferLengthRx = effTxFifoDepth;
}
/* Write the data in Tx FIFO. */
for (i = 0; i < transferLengthRx; i++)
{
*rxBuff++ = (uint8_t) MCSPI_readRxDataReg(baseAddr, chNum);
}
numWordsRead += transferLengthRx;
transferLengthRx = length - numWordsRead;
}
}



Thanks
Rajeev

  • Hi Rajeev,

    The difference between the TXFFE and TXFFF is the FIFO full or empty. If you are using CPU polling, I agree checking for TXFFF (not full) can give you some transmission speed advantage, but the CPU is tied 100% to this task. When you use the interrupt mode or DMA, set up the interrupt source or DMA event based on TXFFE is more efficient and the DMA transfer size is fixed.

    The same principle applies to the RXFFE and RXFFF.

    Best regards,

    Ming