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.

TI-RTOS - SPI and DMA Examples

I have modified the SPI Loopback example provided for the Tiva C TM4C123G, but am having issues when I try and send more than 200 bytes. I eventually will need to send in one communication up to 20kb at 500Kbps.

Before I raise any of the issues I am getting with my altered code. I had a few questions.

1) Are there any other examples or sample code for using SPI/DMA with TI-RTOS?

2) Should I be sending in a burst since I need to be sending up to 20kb (being able to send more than 20kb would be great also), should I being using a ping pong method instead. If so, are there any SPI/DMA TI-RTOS examples that show how to implement a ping pong method?

-----------

P.S. I am not using SPI per se, I am just using the MOSI line to send out Manchester Encoded bits, but it works the exact same way as SPI, I just don¹t need the SPI clock, as timing is contained in the communication.

  • Glenn,

    As far as examples, we currently only have the SPI loopback example available in TI-RTOS. We do however have a SPIMessageQ module and a WiFi driver that utilize the same SPI driver.

    Note that the uDMA control table and the data buffers must be uDMA accessible. I'm not sure if flash memory is accessible on the TM4C123G.

    The SPI driver shouldn't have any problems to send 200 bytes. However, it's only limited by the uDMA to transfer 1024 SPI frames. With that said, if you use 16-bit frames you could get 2048 bytes out of a single SPI_transfer. If you use the SPI driver in "callback" mode, then you can make additional calls to SPI_transfer from within the SPI callback function. You would then just continue from where you left off with the previous transfer.

    I hope this helps.

  • Thanks Tom,

    I will need to send up to 20kb if possible. And there cannot be any break in the transmission, will the SPI callback function you mentioned enable me to achieve this? And is there any sample code available, so i can get an idea on how to implement it?

    Regarding the TM4C123G, it states the following in the Data Sheet;

    The μDMA controller can transfer data to and from the on-chip SRAM. However, because the Flash memory and ROM are located on a separate internal bus, it is not possible to transfer data from the Flash memory or ROM with the μDMA controller

    Was your statement regarding direct access to Flash in reference to the SPIMessageQ module or uDMA and TI-RTOS in general?

    Glenn.

  • Glenn,

    Here's some pseudo code that I just added to the SPI loopback example.

    Void spiCallback (SPI_Handle handle, SPI_Transaction *transaction)
    {
        if (moreDataToSend) {
            transaction->txBuf = nextBuffer;
            SPI_transfer(handle, transaction);
        }
    }
    
    /*
     *  ======== masterTaskFxn ========
     *  Task function for master task.
     *
     *  This task runs at a lower priority after the slave
     *  task to ensure it is ready for a transaction.
     *  Master SPI sends a message to slave and also
     *  receives message from slave. Task for this function
     *  is created statically. See the project's .cfg
     *  file.
     */
    Void masterTaskFxn (UArg arg0, UArg arg1)
    {
        SPI_Handle masterSpi;
        SPI_Transaction masterTransaction;
        SPI_Params params;
        UInt transferOK;
    
        /* Initialize SPI handle as default master */
        SPI_Params_init(&params);
        params.dataSize = 16;
        params.transferMode = SPI_MODE_CALLBACK;
        params.transferCallbackFxn = spiCallback;
        masterSpi = SPI_open(Board_SPI0, NULL);
        if (masterSpi == NULL) {
            System_abort("Error initializing SPI\n");
        }
        else {
            System_printf("SPI initialized\n");
        }
    
        /* Initialize master SPI transaction structure */
        masterTransaction.count = SPI_MSG_LENGTH;
        masterTransaction.txBuf = (Ptr)masterTxBuffer;
        masterTransaction.rxBuf = (Ptr)masterRxBuffer;
    
        /* Initiate SPI transfer */
        transferOK = SPI_transfer(masterSpi, &masterTransaction);
    
        if(transferOK) {
            /* Print contents of master receive buffer */
            System_printf("Master: %s\n", masterRxBuffer);
        }
        else {
            System_printf("Unsuccessful master SPI transfer");
        }
    ...
    }

    Glenn Vassallo said:
    Was your statement regarding direct access to Flash in reference to the SPIMessageQ module or uDMA and TI-RTOS in general?

    Yes. :) The uDMA in general.

  • Thanks Tom, very much appreciated!

    Tom Kopriva said:
    Yes. :) The uDMA in general.

    :-)

  • Hello,

    I need a small help in writing SPI receive handler. Can you please help me in writing receive handler for SPI , since i am using SPI based ADC and i need to receive the ADC data. Please help i am struck with this. I am able to make this working with normal TI driver, but i ma using TI RTOS i am struggling to achieve this.

    Nitesh 

  • Nitesh,

    Please start a new thread with your question. Please clarify what you mean by "normal TI driver" and what is your struggle with TI-RTOS.

    ~Ramsey

  • Hi Ramsey,

    Created new thread, please help. " SPI with DMA or without DMA for external SPI chip(ADC/DAC) "

    Nitesh