AM5718-HIREL: Variable size SPI transaction

Part Number: AM5718-HIREL
Other Parts Discussed in Thread: AM5718

Hello. I am trying to achieve SPI communication between two AM5718 based custom boards, one of which is master (Linux) and the second is slave (TI-RTOS). The slave is able to receive frames from the master for a initial size (transction.count) of SPI transaction. However, when I increase the size of the transaction at runtime, the slave does not receive all the data, rather lesser than the transaction count. More suprsisingly, the slave again starts receiving all of the data when I re-execute this transaction with this larger size. What could be the reason for this? Any help would be appreciated.

  • Hi,

    However, when I increase the size of the transaction at runtime, the slave does not receive all the data, rather lesser than the transaction count.

    Can you please share how you are increasing the transaction count at runtime? What changes you are doing for that?
    Also, please mention what behavior you are seeing when you are increasing the transaction? Is it always sending the same amount of data, no matter how much you increase the transaction at runtime or the amount of data sent varies, but does not match with the transaction count?

    Regards,
    Parth

  • Parth,

    I open a handle for the slave SPI instance at the beginning of the program. I then create a SPI_transaction variable, wherein the 'count' is first set to a given size (say 200). The transaction is then executed the transaction using the 'SPI_transfer' API which works as expected. For the second transfer, the same transaction variable is used but now with the 'count' set to a larger value (say 500). When this transaction is executed, the slave receives some amount of data which does not match with the transaction size. The amount of data received lies between the earlier and newly set 'count', and the amount is not fixed. When the transaction is re-executed with this new size, the slave receives all of the data.

    Regards,

    Jay 

  • Hi Jay,

    Can you confirm that Master is sending the required amount of data after you change the 'count'. This will help us isolate that if the issue is on slave side.

    When the transaction is re-executed with this new size, the slave receives all of the data.

    Also, can you please elaborate a little bit on this? What do you mean by re-execution?

    Regards,
    Parth

  • Parth,

    I have confirmed that the master is sending the required amount of data after the 'count' is changed.

    By re-executing the transaction I mean calling the 'SPI_transfer' API again. The first 'SPI_transfer' call fails to get the correct data sent by the master on the new 'count', but calling the 'SPI_transfer' again gets the correct data.

    Regards,

    Jay

  • Hi Jay,

    Apologies for delay in response. Is this issue still open? If yes, can you please highlight the current state of the issue?
    Also, can you please share a sample code which we can try on our end and replicate the issue?

    Regards,
    Parth

  • Hi Parth,

    Yes the issue is still open. The current state is still as I described earlier wherein 'SPI_transfer' does not work correctly when the 'count' is changed. Attaching a sample code below.

        bool transferCompleted = false;
        uint32_t packetCount = 0;
        SPI_Params gSpiParams;
        gSpiParams.transferMode = SPI_MODE_BLOCKING;
        gSpiParams.bitRate = 5000000;
        gSpiParams.dataSize = 8
        gSpiParams.frameFormat = SPI_POL0_PHA0;
        gSpiParams.mode = SPI_SLAVE;
    
        gSpiHandle = SPI_open(1, &gSpiParams);
        while(transferCompleted == false)
        {
            //First transaction of size 500
            SPI_Transaction transaction;
            transaction.txBuf = txData;
            transaction.rxBuf = rxData;
            transaction.count = 500;
            SPI_transfer(gSpiHandle, transaction); 
            packetCount++;
            /*Do some processing on received data and send an acknowledgement*/
            transaction.txBuf = txData;
            transaction.rxBuf = rxData;
            transaction.count = 20;
            SPI_transfer(gSpiHandle, transaction); 
    
            UART_printf("\nAck sent\n");
            memset(txData, 0, sizeof(txData));
            memset(rxData, 0, sizeof(rxData));
            
            if (packetCount == 1000)
            {
                transferCompleted = true;
            }
    
        }

    Regards,

    Jay