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.

4-wire SPI communication using RTOS on MSP432

Other Parts Discussed in Thread: CC1310

Hi Team,

I am trying to establish SPI communication between MSP432 and CC1310 radio using the 4-wire concept for MSP432.

The MSP432 is acting as Master SPI and CC1310 to be acting as Slave SPI.

The example code for SPI MSP432 is based on 3-wire.

I am finding it hard to convert it o 4-wire. As I want to use the CS concept for MSP432 I tried to modify the code.

But the hardware attribute structure defined in the "MSP_EXP432P401R.c" file does not have the element where we can mention whic pin is used as CS.

the same thing is available for SDSPI peripheral.

Please will need your guidance to make SPI 4-wire communication to be established on the MSP432 using RTOS.

The CC1310 is already designed to act as Slave and it is working fine.

Thank you

Vikram

  • Hi Vikram,

    Please take a look at this thread.

    e2e.ti.com/.../1956741

    Regards,

    David
  • Hi David,

    I went through the document earlier but when I implement it does not work at all. Although the master is able to transfer as I see the status of the transferOK flag to be positive nothing is received on the receiver end which is CC1310 board.
    Can't see how to check or resolve this issue.

    Thank you
    Vikram
  • I debugged the code and found that my spi length was incorrect and also the connections were incorrect.
    So I reworked on both part.
    Now atleast the communication is happening but incorrect data is received.

    Firstly, if I keep spi length to 26 it triggers on every second data packet sent i& if I increase length to 512 (which is what needed in my application) it triggers on every third data packet.
    Secondly, data received is all incorrect.

    Please suggest any input.
    Thank you
    Vikram
  • Hi David,

    While debugging the code I found two things.

    1. Every 2nd SPI communication is missued

    2. Data received on the slave is right shifted by 3 for all data.

    Don't understand why this could be happening.

    I have used the Port pin P5.2 as CS for the slave to be enabled before the master can send any data.

    Here the slave is CC1310 and master is MSP432.

    I simply used the spi loopback example and modified as per the requirements.

    I have attached the code if you can get time to check and let me know would be greatful and appreciated.

    Thank you

    Vikram

    /*
     * Copyright (c) 2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *     its contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== spiloopback.c ========
     */
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <stdio.h>
    #include <string.h>
    
    #include <xdc/runtime/System.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Event.h>
    #include <ti/sysbios/knl/Semaphore.h>
    
    /* TI-RTOS Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SPI.h>
    #include <ti/drivers/PIN.h>
    //#include <ti/driverlib/cpu.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    #define SPI_MSG_LENGTH    250
    #define TASKSTACKSIZE     768
    #define KEYPRESS_TASK_STACK_SIZE 1024
    #define KEYPRESS_TASK_PRIORITY   3
    
    /* Allocate buffers in .dma section of memory for concerto devices */
    #ifdef MWARE
    #pragma DATA_SECTION(masterRxBuffer, ".dma");
    #pragma DATA_SECTION(masterTxBuffer, ".dma");
    #pragma DATA_SECTION(slaveRxBuffer, ".dma");
    #pragma DATA_SECTION(slaveTxBuffer, ".dma");
    #endif
    
    //Task_Struct task0Struct, task1Struct;
    //Char task0Stack[TASKSTACKSIZE], task1Stack[TASKSTACKSIZE];
    
    SPI_Handle masterSpi;
    SPI_Transaction masterTransaction;
    
    static Task_Params keypressTaskParams;
    Task_Struct keypressTask;    /* not static so you can see in ROV */
    static uint8_t keypressTaskStack[KEYPRESS_TASK_STACK_SIZE];
    
    Event_Struct keyPressEvent;  /* not static so you can see in ROV */
    static Event_Handle keyPressEventHandle;
    
    //char masterRxBuffer[SPI_MSG_LENGTH];
    //char masterTxBuffer[SPI_MSG_LENGTH];
    uint8_t  masterRxBuffer[SPI_MSG_LENGTH];
    uint8_t masterTxBuffer[SPI_MSG_LENGTH];
    
    bool transferOK;
    uint8_t delay = 0;
    
    /* Events used in the application */
    typedef enum {
        KeyPressUp_Event = Event_Id_00,
        KeyPressDown_Event = Event_Id_01,
        KeyPressAll_Event = KeyPressUp_Event + KeyPressDown_Event,
    } KeyPressEvent;
    
    /***** Prototypes *****/
    void spiBusTransmitFinished(SPI_Handle handle, SPI_Transaction *transaction);
    void spiBusTransmit();
    void spiBus_Init();
    static void spiTaskFunction(UArg arg0, UArg arg1);
    
    void spiBus_Init(){
    
         Event_Params eventParam;
         Event_Params_init(&eventParam);
         Event_construct(&keyPressEvent, &eventParam);
         keyPressEventHandle = Event_handle(&keyPressEvent);
    
    
         /* Create the keypress task */
         Task_Params_init(&keypressTaskParams);
         keypressTaskParams.stackSize = KEYPRESS_TASK_STACK_SIZE;
         keypressTaskParams.priority = KEYPRESS_TASK_PRIORITY;
         keypressTaskParams.stack = &keypressTaskStack;
         Task_construct(&keypressTask, spiTaskFunction, &keypressTaskParams, NULL);
    }
    
    static void spiTaskFunction(UArg arg0, UArg arg1)
    {
         //GPIO_write(Spi_CHIP_SELECT, Spi_ENABLED);
    
         SPI_Params masterSpiParams;
    
         SPI_Params_init(&masterSpiParams);
         masterSpiParams.transferMode = SPI_MODE_CALLBACK;
         masterSpiParams.mode = SPI_MASTER;
         masterSpiParams.frameFormat = SPI_POL1_PHA1;
         masterSpiParams.bitRate = 1000000;
         masterSpiParams.transferCallbackFxn = spiBusTransmitFinished;
    
         masterSpi = SPI_open(Board_SPI0, &masterSpiParams);
         if (masterSpi == NULL) {
             System_abort("Error initializing SPI\n");
         }
         else {
             System_printf("SPI initialized\n");
         }
    
         strcpy((char*)masterTxBuffer,"Hello, This is Master SPI");
         /* Initialize master SPI transaction structure */
         masterTransaction.count = SPI_MSG_LENGTH;
         masterTransaction.txBuf = (Ptr)masterTxBuffer;
         masterTransaction.rxBuf = (Ptr)masterRxBuffer;
         masterTransaction.arg = NULL;
    
     	while(1)
         {
             /* Wait for event */
             uint32_t events = Event_pend(keyPressEventHandle, 0, KeyPressAll_Event, BIOS_WAIT_FOREVER);
    
             /* If new ADC value, send this data */
             if (events & (KeyPressUp_Event|KeyPressDown_Event))
             {
                 /* Initiate transmission */
            	 spiBusTransmit();
                 SPI_transfer(masterSpi, &masterTransaction);
             }
         }
    }
    void spiBusTransmit(){
        GPIO_write(Spi_CHIP_SELECT, Spi_ENABLED);
        /*if (delay++ == 100) {
            delay = 0;
        }*/
        //CPUdelay((uint32_t)((48000000/3)*0.050f));
    	transferOK = SPI_transfer(masterSpi, &masterTransaction);
    }
    
    void spiBusTransmitFinished(SPI_Handle handle, SPI_Transaction *transaction){
    	GPIO_toggle(Board_LED0);
    	//gpioToggle(Board_LED3);
        GPIO_write(Spi_CHIP_SELECT, Spi_DISABLED);
    }
    
    /*
     *  ======== gpioButtonFxn0 ========
     *  Callback function for the GPIO interrupt on Board_BUTTON0.
     */
    void gpioButtonFxn0(unsigned int index)
    {
    	uint8_t count = 0;
        /* Simple debounce logic, only toggle if the button is still pushed (low) */
        if (delay++ == 100) {
            delay = 0;
        }
    	//CPUdelay((uint32_t)((48000000/3)*0.050f));
    	strcpy((char*)masterTxBuffer,"Master key up is pressed");
    	for (count = 0;count<SPI_MSG_LENGTH;count++)
    	{
    		//masterTxBuffer[count++] = 0xAA;
    		masterTxBuffer[count] = 123;
    	}
    	//GPIO_toggle(Board_LED0);
    	Event_post(keyPressEventHandle, KeyPressUp_Event);
    }
    
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
    
        /* Call board init functions. */
        Board_initGeneral();
        Board_initGPIO();
        Board_initSPI();
    
        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();
        System_printf("This example requires external wires to be connected to the "
                      "header pins. Please see the Getting Started Guide for "
                      "details.\n");
        /* SysMin will only print to the console when you call flush or exit */
        System_flush();
    
        /* install Button callback */
        GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);
    
        /* Enable interrupts */
        GPIO_enableInt(Board_BUTTON0);
        //GPIO_enableInt(Board_BUTTON1);
    
        /* Initialize spi transmission task */
        spiBus_Init();
    
        /* Start BIOS */
        BIOS_start();
    
        return (0);
    }
    

  • Hi Vikram,

     I ran you code on  my side (with a couple of MSP432 LP's) and I could not find any problem. Messages were transmitted and received correctly.

    The only thing that I changed was the frame format to:

         SPI_Params_init(&masterSpiParams);
         masterSpiParams.transferMode = SPI_MODE_CALLBACK;
         masterSpiParams.mode = SPI_MASTER;
         masterSpiParams.frameFormat = SPI_POL0_PHA0;
         masterSpiParams.bitRate = 1000000;

    So my guess is that the SPI configuration on your CC1310 is not matching the MSP432 and that's why you are missing some bytes. What is the SPI configuration that you are using for the CC1310??

      Best regards,

       David

  • Thank you David.

    I changed the configuration on MSP432 to SPI_POL0_PHA0 but it did not worked. The configuration on the CC1310 is PHA1_POL1.

    But when I changed to POL0_PHA1 it worked and I believe it is because the Master CS line is output and the Slave CS is input and the clock of Master is configured as output and that of slave is configured as input.

    The issue is now resolved.

    Thank you for the input you gave.

    Regards,

    Vikram

**Attention** This is a public forum