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/LAUNCHXL-CC1310: SPI communication between master and slave

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

Tool/software: TI-RTOS

Dear community,

for my project I need to implement a SPI communication between a Master and some Slaves.

I started with some basic examples from here.

Master: Should send "Hello World" every 3 seconds.

    Debugging: The status is "SPI_TRANSFER_COMPLETED", every time.

    GPIO_init();
    SPI_init();

    SPI_Handle handle;
    SPI_Params params;
    SPI_Transaction transaction;
    uint8_t txBuf[] = "Hello World";    // Transmit buffer
    uint8_t rxBuf[11];                  // Receive buffer

    // Init SPI and specify non-default parameters
    SPI_Params_init(&params);
    params.bitRate     = 1000000;
    params.frameFormat = SPI_POL1_PHA1;
    params.mode        = SPI_MASTER;

    // Configure the transaction
    transaction.count = sizeof(txBuf);
    transaction.txBuf = txBuf;
    transaction.rxBuf = rxBuf;

    // Open the SPI and perform the transfer
    handle = SPI_open(Board_SPI0, &params);
    if (handle == NULL) {
        /* Error opening SPI */
    }

    while (1) {
        sleep(3);
        GPIO_toggle(Board_GPIO_LED0);

        SPI_transfer(handle, &transaction);
        transaction.txBuf = txBuf;
    }

-----------------------------------------------------------------------------------------------

Slave: Should receive the data and compares it

           Debugging: SPI_transfer() never leaves its blocking mode.

    GPIO_init();
    SPI_init();

    SPI_Handle handle;
    SPI_Params params;
    SPI_Transaction transaction;
    uint8_t rxBuf[100];     // Receive buffer
    uint8_t *s;

    // Init SPI and specify non-default parameters
    SPI_Params_init(&params);
    params.bitRate     = 1000000;
    params.frameFormat = SPI_POL1_PHA1;
    params.mode        = SPI_SLAVE;

    // Configure the transaction
    transaction.count = 100;
    transaction.txBuf = NULL;
    transaction.rxBuf = rxBuf;

    // Open the SPI and perform the transfer
    handle = SPI_open(Board_SPI0, &params);
    if (handle == NULL) {
        /* Error opening SPI */
    }

    while (1) {
         SPI_transfer(handle, &transaction);

         s = strstr(rxBuf, "Hello World");      // search for string "Hello World" in buff
         if (s != NULL)                     // if successful then s now points at "Hello World"
         {
             GPIO_write(Board_GPIO_LED1, Board_GPIO_LED_ON);
         }                                  // index of "Hello World" in buff can be found by pointer subtraction

    }

The launchpads were wired as seen below.

As I have seen in the CC1310_LAUNCHXL.h (line 131), the chip select (SPI CS, DIO 11) is unassigned.

Is an assignment required? And if so, how should it be implemented? Do I have to use the SPI_control() function with

SPICC26XXDMA_SET_CSN_PIN? If yes how is it called correctly?

  • Hi,

    Timo J0 said:
    Is an assignment required? And if so, how should it be implemented?

    Yes, it needs an assignment for this pin. Either edit CC1310_LAUNCHXL.h and assign a pin or use SPI_control(). There is a code snippet in the SPI driver API documentation that you can copy-paste. It boils down to:

    PIN_Id csnPin1  = PIN_ID(Board_CSN_1);
    SPI_control(handle, SPICC26XXDMA_SET_CSN_PIN, &csnPin1);

    Looking at your schematic, you need to cross MOSI and MISO and you need to add a connection for the CS pins.

  • Hi Richard,

    thanks alot for your answer.
    Both variants are solving my problem with the following wiring:

    MISO = MISO
    MOSI = MOSI
    CS = CS or CS = GND for perma active slave
    CLK = CLK

    Best regards,

    Timo