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.

SPI Communication issue

Other Parts Discussed in Thread: MSP430F5529
Hi there,

I'm trying to communicate to SRAM(http://ww1.microchip.com/downloads/en/DeviceDoc/20005142C.pdf) using MSP430F5529LP over SPI(MSP_EXP430F5529LP_SPIB1). Proper communication is not happening.

Please review the code and help me.














/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>

/* TI-RTOS Header files */
#include <gpio.h>
#include <ti/drivers/SPI.h>

/* Example/Board Header files */
#include "Board.h"

SPI_Handle spiHandle;

uint8_t             rxBuffer[10];
uint8_t             txBuffer[10];
uint8_t             dummyBuffer[1];
SPI_Transaction     spiTransaction;
SPI_Params  SPIparams;

Void taskFxn (UArg arg0, UArg arg1)
{

    System_printf("Starting the SPI loop-back example\nSystem provider is set to");

/* INITIALISE SRAM */

    		GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0);

                    txBuffer[0] = 0x01;
                    txBuffer[1] = 0x40;
                    spiTransaction.count = 2;
                    spiTransaction.rxBuf = dummyBuffer;
                    spiTransaction.txBuf = txBuffer;
                    if ( !SPI_transfer(spiHandle, &spiTransaction) )
                    {
                    	while(1);
                    }

            GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0);


/* WRITE TO SRAM */
    		GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0);

    		   		txBuffer[0] = 2;
    		   		txBuffer[1] = 0;
    		   		txBuffer[2] = 0;
    		   		txBuffer[3] = 0;
    		   		txBuffer[4] = 5;
    		   		txBuffer[5] = 6;
    		   		txBuffer[6] = 2;
    		   		txBuffer[7] = 1;
                    spiTransaction.count = 8;
                    spiTransaction.rxBuf = dummyBuffer;
                    spiTransaction.txBuf = txBuffer;
                    if ( !SPI_transfer(spiHandle, &spiTransaction) )
                    {
                    	while(1);
                    }

            GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0);


/* REAM FROM SRAM */
    		GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0);

    		   		txBuffer[0] = 3;
    		   		txBuffer[1] = 0;
    		   		txBuffer[2] = 0;
    		   		txBuffer[3] = 0;
                    spiTransaction.count = 4;
                    spiTransaction.rxBuf = dummyBuffer;
                    spiTransaction.txBuf = txBuffer;
                    if ( !SPI_transfer(spiHandle, &spiTransaction) )
                    {
                    	while(1);
                    }

                    spiTransaction.count = 4;
                    spiTransaction.rxBuf = rxBuffer;
                    spiTransaction.txBuf = dummyBuffer;
                    if ( !SPI_transfer(spiHandle, &spiTransaction) )
                    {
                    	while(1);
                    }

            GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0);


    /* Deinitialize SPI */
    SPI_close(spiHandle);

    System_printf("Done\n");

    System_flush();
}


/*
 *  ======== main ========
 */
int main(void)
{
    /* Call board init functions. */
    Board_initGeneral();
    Board_initGPIO();
    Board_initSPI();

    /* Turn on user LED */
   // GPIO_write(Board_LED0, Board_LED_ON);

    System_printf("Starting the SPI loop-back example\nSystem provider is set to"
                  " SysMin. Halt the target to view any SysMin contents in ROV.\n");
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    SPIparams.frameFormat = SPI_POL0_PHA1;
    SPIparams.bitRate = 1000000;
    SPIparams.mode = SPI_MASTER;
    SPIparams.transferCallbackFxn = NULL;
    SPIparams.dataSize = 8;
    SPIparams.transferMode = SPI_MODE_BLOCKING;
    SPIparams.transferTimeout = SPI_WAIT_FOREVER;

    /* Initialize SPI handle as default master */
    spiHandle = SPI_open(Board_SPI1, &SPIparams);
    if (spiHandle == NULL) {
        System_abort("Error initializing SPI\n");
    }
    else {
        System_printf("SPI initialized\n");
    }

    /* Start BIOS */
    BIOS_start();

    return (0);
}

I'm using CCSv6.1 with latest TI-RTOS for MSP430.

Thank you...



  • Hi,

    Which version of TI-RTOS are you using? Which hardware platform are you on?

    Are you just trying to run an out of the box SPI example that ships with TI-RTOS?

    Steve
  • Hi Steve,

    Here are my setup details:

    RTOS version: tirtos_msp43x_2_12_01_33

    MSP used: MSP430F5529(using launchpad)

    There are no example SPI driver for MSP430F5529 LP found in tirtos_msp43x_2_12_01_33.

    I'm modified SPI example posted by  here: https://e2e.ti.com/support/embedded/tirtos/f/355/t/350499#pi317008=2

    Here is my full SPI project folder. 

    0755.rtos_spi.zip

  • Rahul,

    Are you still stuck on this issue?

    Steve
  • Yes Steven, I'm still facing the issue.

    Below is the updated project.

    6574.rtos_spi.zip

    Please let me know your findings/suggestions.

    Thank you!

  • Hi Rahul,

    I spoke to one of my colleagues about this. The reason there is no SPI example is because the SPI loopback example uses 2 SPI controllers (one SPI Master and one SPI Slave) and need to be connected together externally.

    Each controller requires 2 DMA channels, but there are only 3 DMA channels available on the 5529.  So, this limitation prevents that example from working on the 5529.

    However, the board files are set up for proper use of SPI (i.e. SPI driver is supported on the 5529).

    His suggestion is that you refer to the WiFi examples, which make use of SPI on the 5529.  In particular, the WiFI host driver is really what you should look at:

    packages/ti/drivers/wifi/WiFiCC3100.c

    You could also chop up the spiloopback example to use just one SPI controller and connect the MISO and MOSI pins together.

    Hope this helps ...

    Steve

  • Hi Steve,

    Issue solved!

    There was problem in reading data from slave.

    Reading data from slave look like this now.

    //Select slave
    GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN0);

    //Send command and address
    txBuffer[0] = 3;
    txBuffer[1] = 0;
    txBuffer[2] = 0;
    txBuffer[3] = 0;

    spiTransaction.count = 4;
    spiTransaction.rxBuf = NULL;
    spiTransaction.txBuf = txBuffer;
    if ( !SPI_transfer(spiHandle, &spiTransaction) )
    {
    while(1);
    }

    //Receive data
    spiTransaction.count = 4;
    spiTransaction.rxBuf = rxBuffer;
    spiTransaction.txBuf = NULL;
    if ( !SPI_transfer(spiHandle, &spiTransaction) )
    {
    while(1);
    }

    //Deselect slave
    GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN0);


    Thanks,

  • Hi Steve,

    As per SPI API, by passing SPI_Params as NULL to "SPI_open", it will take frame format as "frameFormat = SPI_POL0_PHA0".

    In SPI.h file.

    extern SPI_Handle SPI_open(unsigned int index, SPI_Params *params);

    /*!
    * @brief Function to initialize the SPI_Params struct to its defaults
    *
    * @param params An pointer to SPI_Params structure for
    * initialization
    *
    * Defaults values are:
    * transferMode = SPI_MODE_BLOCKING
    * transferTimeout = SPI_WAIT_FOREVER
    * transferCallbackFxn = NULL
    * mode = SPI_MASTER
    * bitRate = 1000000 (Hz)
    * dataSize = 8 (bits)
    * frameFormat = SPI_POL0_PHA0

    But When I loaded code with passing NULL as SPI parameter, like this here,

     SPI_open(Board_SPI1, NULL);

    It will set, clock polarity as '0' and clock phase as '1'

    So, I think, This erratum needs to be corrected.

    Thank you...