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.

RTOS/SW-EK-TM4C129EXL: SPI Datatransfer Issues

Part Number: SW-EK-TM4C129EXL
Other Parts Discussed in Thread: EK-TM4C129EXL

Tool/software: TI-RTOS

I am working with EK-TM4C129EXL Eval kit. I am trying to send the data from one array to another array through SPI protocol. The data from transmitBuffer(array1) is not sent to receiveBuffer(array2). I had also created a boolean variable to check if the SPI transactions complete. The transaction is complete but the data is not transferred to the second array.  I hereby attach the code file.



/* XDCtools Header files */ #include <xdc/std.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> /* TI-RTOS Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/SPI.h> #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/family/arm/m3/Hwi.h>
/* Board Header file */ #include "Board.h" #include <inc/hw_memmap.h> #include <inc/hw_types.h> #include <inc/hw_ssi.h> #include <driverlib/ssi.h> #include <driverlib/udma.h> #include <driverlib/sysctl.h>
#define TASKSTACKSIZE 1024 UChar transmitBuffer[8] = {0,1,2,3,4,5,6,7}; UChar receiveBuffer[8]; Task_Struct task0Struct; Char task0Stack[TASKSTACKSIZE]; Bool transferOK; Void spiDataSend() { SPI_Handle spi; SPI_Params spiParams; SPI_Params_init(&spiParams); spiParams.transferMode = SPI_MODE_BLOCKING; spiParams.transferCallbackFxn = NULL; spi = SPI_open(Board_SPI0, &spiParams); if (spi == NULL) { /* Error opening SPI */ } SPI_Transaction spiTransaction; spiParams.dataSize = 8; /* dataSize can range from 4 to 8 bits */ spiTransaction.count = 8; spiTransaction.txBuf = transmitBuffer; spiTransaction.rxBuf = receiveBuffer; transferOK = SPI_transfer(spi, &spiTransaction); if (transferOK) { /* Error in SPI transfer or transfer is already in progress */ System_printf("SPI Transfer successful \n"); // This message gets printed on console but the receiveBuffer is empty with values 0. System_flush(); } SPI_close(spi); } int main(void) { Task_Params taskParams;
/* Call board init functions */ Board_initGeneral(); Board_initGPIO(); Board_initSPI(); /* Construct spiDataSend Task thread */ Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; Task_construct(&task0Struct, (Task_FuncPtr)spiDataSend, &taskParams, NULL); BIOS_start(); return (0); }

  • Hello Naveen,

    Are you trying to do SPI Loopback? That is what your setup looks like to me.

    If so, you need to enable Loopback mode on SSI0 which is likely not handled by TI-RTOS calls as we don't have that feature in TivaWare either. To do so you need to do the following:

        // Enable Loopback mode on SSI0
        // There is no TivaWare function for this
        HWREG(SSI0_BASE + SSI_O_CR1) |= 1u;

    Note: I am assuming Board_SPI0 correlates to SSI0_BASE

    If that doesn't resolve the issue, then can you scope the SSI lines to ensure the data packet is being output correctly on the lines? It sounds like the TX is happening correctly but let's be 100% sure of that before debugging the RX portion further.

  • Hello Ralph,

    • I am not trying out SPI-Loop back example.
    • I am trying to connect micro controller to slave device.
    • Hence micro controller would be master and another module having SPI capability will be slave.
    • I need to transfer array of data to the Slave module through SPI.
    • In such a case I would prefer storing data in transmitBuffer[ ] and try to send that data to the slave module as follows.   

        char transmitBuffer[] = {0,1,2,3,4,5,6,7}
        spiTransaction.count = 8;
        spiTransaction.txBuf =  transmitBuffer;
        spiTransaction.rxBuf =  receiveBuffer;
        SPI_transfer(spi, &spiTransaction);

    spiTransaction.txBuf = transmitBuffer;
    As of my understanding in this statement, txBuf is the pointer to transmitBuffer...

    spiTransaction.rxBuf = receiveBuffer;
    As of my understanding in this statement, rxBuf is the pointer to receiveBuffer... What is the significance of receiveBuffer??? .

    SPI_transfer(spi, &spiTransaction);
    What happens after execution of this line??? Do the data from the transmitBuffer will be moved to receiveBuffer???

    • I want to transfer array of data to SSI1TX(MOSI) pin of the controller, I configured all the SSI1 port correctly.
    • Is that any kind of particular array to which I need to send the data so that It can be transferred to the slave module

  • Hello Naveen,

    Naveen Kumar29 said:
    As of my understanding in this statement, txBuf is the pointer to transmitBuffer...

    Correct.

    Naveen Kumar29 said:
    As of my understanding in this statement, rxBuf is the pointer to receiveBuffer... What is the significance of receiveBuffer??? .

    SPI is bi-directional, so, that is to receive data on the SSI port from the slave device.

    Naveen Kumar29 said:
    What happens after execution of this line??? Do the data from the transmitBuffer will be moved to receiveBuffer???

    No, the receiveBuffer will only get data when it is received over the SSI lines. So if the execution goes without issue (i.e. the transfeOK check passes) that means your data was sent over SSI1TX successfully. If you scope your SSI lines, you should see the data being sent to your slave module.