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/CC2640R2F: App fails to establish connection when SPI has been initialised

Part Number: CC2640R2F


Tool/software: TI-RTOS

Hi,

I am having a bit of an issue here. I now need to use the SPI for interfacing some sensor. If I called the "SPI_init()" in the task's main, then for some reason, the app(nRFConnect) is unable to establish a connection to the device. However, when I remove the SPI_init( ), then everything starts to work normally. 

Any idea what issue calling the SPI_init() might be causing? 

  • Hi Vinay,

    1. What version of the CC240R2 SDK are you using?

    2. What example project did you base your project on?

    3. Is SPI running in a separate task or in the application task?

  • Can you post code snippet so we can better assist you? 

  • Hi Marie,

    1.  simplelink_cc2640r2_sdk_2_40_00_32

    2. Multi-role

    3. Apart from the tasks that already existed in the example, I had created a new task for using the sensor controller and handling some other application related functions. So I initialize the SPI in that new task I created as shown below.

    static void AppTaskFxn(UArg a0, UArg a1)
    {
        /* Msg object for IPC */
        MsgObj msgPktRec;
        grSigState_t grState = SIG_LOW;
    
        /* Initialize the sensor controller */
        AppInitSensorController();
    
        /* Initialize GPIO Module */
        GPIO_Init();
        //GPIO_SelectRelay(ALL_RELAYS);
        //GPIO_triggerOffAllRelays();
    
        /* Init Pkt */
        Pkt_Init();
    
        /* Init SPI */
        SPI_Initialize();
    
        /* Init h/w timer */
        //initHwTimer(TMR_A);
    
        while(1)
        {
         ...
        }
    }

    As requested by Christin, below are some of the code I used to initialize and use the SPI.

    1. Pin initializations

    GPIO_PinConfig gpioPinConfigs[] = {
        /* Input pins */
        GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG,  /* RESERVED */
        GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG,  /* RED SIG INPUT */
    
        GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_MASTER_READY */
        GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,  /* CC2640R2_LAUNCHXL_SPI_SLAVE_READY */
    
        /* Output pins */
        GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG,  /* RELAY_1 */
        GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG,  /* RELAY_2 */
        //GPIOCC26XX_DIO_08 | GPIO_DO_NOT_CONFIG,  /* RELAY 3 */
        //GPIOCC26XX_DIO_09 | GPIO_DO_NOT_CONFIG,  /* RELAY 4 */
        GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG,  /* TMP116_EN */
    
        /* SPI Flash CSN */
        GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG,
    
        /* SD CS */
        GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG,
    
        /* Sharp Display - GPIO configurations will be done in the Display files */
        GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */
        GPIOCC26XX_DIO_22 | GPIO_DO_NOT_CONFIG, /* LCD power control */
        GPIOCC26XX_DIO_23 | GPIO_DO_NOT_CONFIG, /*LCD enable */
        //GPIOCC26XX_DIO_11 | GPIO_DO_NOT_CONFIG,
    };
    
    const PIN_Config BoardGpioInitTable[] = {
    
        CC2640R2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,         /* LED initially off */
        CC2640R2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,         /* LED initially off */                                  /* Button is active low */
        CC2640R2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_BM_HYSTERESIS,                                                  /* Button is active low */
        CC2640R2_LAUNCHXL_DIO15 | PIN_INPUT_EN | PIN_PULLUP|PIN_BM_HYSTERESIS,
        CC2640R2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN,    /* External flash chip select */
        CC2640R2_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN,                                                /* UART RX via debugger back channel */
        CC2640R2_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,                          /* UART TX via debugger back channel */
        //CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master out - slave in */
        //CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master in - slave out */
        CC2640R2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master out - slave in */
        CC2640R2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master in - slave out */
        CC2640R2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,                                             /* SPI clock */
    
        PIN_TERMINATE
    };
    
    /* SPI */
    #define CC2640R2_LAUNCHXL_SPI_FLASH_CS          IOID_20
    #define CC2640R2_LAUNCHXL_FLASH_CS_ON           0
    #define CC2640R2_LAUNCHXL_FLASH_CS_OFF          1
    
    /* SPI Board */
    #define CC2640R2_LAUNCHXL_SPI0_MISO             IOID_8          /* RF1.20 */
    #define CC2640R2_LAUNCHXL_SPI0_MOSI             IOID_9          /* RF1.18 */
    #define CC2640R2_LAUNCHXL_SPI0_CLK              IOID_10         /* RF1.16 */
    #define CC2640R2_LAUNCHXL_SPI0_CSN              IOID_11
    #define CC2640R2_LAUNCHXL_SPI1_MISO             PIN_UNASSIGNED
    #define CC2640R2_LAUNCHXL_SPI1_MOSI             PIN_UNASSIGNED
    #define CC2640R2_LAUNCHXL_SPI1_CLK              PIN_UNASSIGNED
    #define CC2640R2_LAUNCHXL_SPI1_CSN              PIN_UNASSIGNED
    
    /*!
     *  @def    CC2640R2_LAUNCHXL_GPIOName
     *  @brief  Enum of GPIO names
     */
    typedef enum CC2640R2_LAUNCHXL_GPIOName {
        CC2640R2_LAUNCHXL_GPIO_S1 = 0,          // GREEN SIG INPUT
        CC2640R2_LAUNCHXL_GPIO_S2,              // RED SIG INPUT
        CC2640R2_LAUNCHXL_SPI_MASTER_READY,
        CC2640R2_LAUNCHXL_SPI_SLAVE_READY,
        CC2640R2_LAUNCHXL_GPIO_LED_GREEN,       // RELAY_1
        CC2640R2_LAUNCHXL_GPIO_LED_RED,         // RELAY_2
        CC2640R2_LAUNCHXL_GPIO_DIO_8,           // RELAY_3
        CC2640R2_LAUNCHXL_GPIO_DIO_9,           // RELAY_4
        CC2640R2_LAUNCHXL_GPIO_TMP116_EN,
        CC2640R2_LAUNCHXL_GPIO_SPI_FLASH_CS,
        CC2640R2_LAUNCHXL_SDSPI_CS,
        CC2640R2_LAUNCHXL_GPIO_LCD_CS,
        CC2640R2_LAUNCHXL_GPIO_LCD_POWER,
        CC2640R2_LAUNCHXL_GPIO_LCD_ENABLE,
        CC2640R2_LAUNCHXL_GPIOCOUNT,
        CC2640R2_LAUNCHXL_CS
    } CC2640R2_LAUNCHXL_GPIOName;

    2. SPI code

    /* spiUser static Lib variables */
    static SPI_Handle      masterSpi;
    static SPI_Params      spiParams;
    

    /****************************************************************
     * Function Name : SPI_Initialize
     * Description   : Initialize the SPI bus
     * Returns       : None
     * Params        : None
     ****************************************************************/
    void SPI_Initialize(void)
    {
        SPI_init();
        SPI_Params_init(&spiParams);
        SPI_InitParams(&spiParams, SPI_BIT_RATE, SPI_FRAME_SIZE, SPI_MODE_BLOCKING, SPI_MASTER,
                       SPI_POL0_PHA0, NULL);
        masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
        if (masterSpi == NULL)
        {
    #ifdef ENABLE_DBG_UART
            Display_print0(dispHandle, 30, 0, "SPI Init Failed !!!");
    #endif
        }
    }
    
    /****************************************************************
     * Function Name : SPI_InitParams
     * Description   : Initialize I2C instance object
     * Returns       : None
     * Params           @spiObjPtr: Ptr to spi object
     *                  @bitRate: bus speed
     *                  @txMode: execution mode
     *                  @mode: SPI mode
     *                  @format: Frame format
     *                  @SPI_CbFunc: Callback function
     ****************************************************************/
    void SPI_InitParams(SPI_Params *spiObjPtr, uint32_t  bitRate, uint32_t dataSize, SPI_TransferMode txMode,
                        SPI_Mode mode,SPI_FrameFormat format,
                        void (*SPI_CbFunc)(SPI_Handle, SPI_Transaction *transaction))
    {
        spiObjPtr->bitRate = bitRate;
        spiObjPtr->dataSize = dataSize;
        spiObjPtr->transferMode = txMode;
        spiObjPtr->mode = mode;
        spiObjPtr->frameFormat = format;
        spiObjPtr->transferCallbackFxn = SPI_CbFunc;
    }
    

    - Vinay

  • Hi,

    I see you are using blocking mode, then in this case, the task SPI will wait until it gets something while blocking other tasks.

    I suggest you to take a look at our simple_serial_socket examples, even though the examples is made for UART, but the concept of integrating with BLE stack is the same.

    https://github.com/ti-simplelink/ble_examples/tree/simplelink_cc2640r2_sdk-2.20/examples/rtos/CC2640R2_LAUNCHXL/bleapps/simple_serial_socket_client

  • Hi Christin,

    I have a question,  as mentioned earlier, even just calling the SPI_Init( ) api leads to the issue while not performing any transactions.

    When you say, SPI will block until it gets back something,  I believe this is only valid when a transfer is performed. But, I am not making any calls to a transfer, I just initialize the SPI module and I am not sure how that can block the tasks?

    Either way, I will try with the non blocking call-back method tomorrow and come back on the results.

  • Hi Christin,

    I configured the SPI to non-blocking mode. The issue still seems to persist, but this time, the connection does establish and then the App keeps trying to discover services (loading discovery) for a while and then disconnects. During the loading discovery,  below is the terminal output:

    0x546C0E9F02EC
    Connected to 1 maxNumBleConns 1
    Non-Connectable Advertising Started !!!

    Param Update 0
    Addr: 0x57583209E1FB ConnHdl: 0 ConnRole:0x04
    GATT Server/Peripheral Rx MTU size: 65


    After a while, it gets disconnected and below output I get.

    0x546C0E9F02EC
    Connected to 0
    Connectable Advertising Started !!!

    Disconnected!
    Addr: 0x57583209E1FB ConnHdl: 0 ConnRole:0x04
    GATT Server/Peripheral Rx MTU size: 65

     

    Some code for your reference, no major changes apart from assigning a callback and changing to call back mode as shown below:

    /*
     *  ======== transferCompleteFxn ========
     *  Callback function for SPI_transfer().
     */
    void transferCompleteFxn(SPI_Handle handle, SPI_Transaction *transaction)
    {
        /* Do Nothing */
    }
    
    /****************************************************************
     * Function Name : SPI_Initialize
     * Description   : Initialize the SPI bus
     * Returns       : None
     * Params        : None
     ****************************************************************/
    void SPI_Initialize(void)
    {
        SPI_init();
        SPI_Params_init(&spiParams);
        SPI_InitParams(&spiParams, SPI_BIT_RATE, SPI_FRAME_SIZE, SPI_MODE_CALLBACK, SPI_MASTER,
                       SPI_POL0_PHA0, transferCompleteFxn);
        masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
        if (masterSpi == NULL)
        {
    #ifdef ENABLE_DBG_UART
            Log_info0("Error initializing master SPI\r\n");
    #endif
        }
    }
    
    /****************************************************************
     * Function Name : SPI_InitParams
     * Description   : Initialize I2C instance object
     * Returns       : None
     * Params           @spiObjPtr: Ptr to spi object
     *                  @bitRate: bus speed
     *                  @txMode: execution mode
     *                  @mode: SPI mode
     *                  @format: Frame format
     *                  @SPI_CbFunc: Callback function
     ****************************************************************/
    void SPI_InitParams(SPI_Params *spiObjPtr, uint32_t  bitRate, uint32_t dataSize, SPI_TransferMode txMode,
                        SPI_Mode mode,SPI_FrameFormat format,
                        void (*SPI_CbFunc)(SPI_Handle, SPI_Transaction *transaction))
    {
        spiObjPtr->bitRate = bitRate;
        spiObjPtr->dataSize = dataSize;
        spiObjPtr->transferMode = txMode;
        spiObjPtr->mode = mode;
        spiObjPtr->frameFormat = format;
        spiObjPtr->transferCallbackFxn = SPI_CbFunc;
    }
    

    Then I called the SPI_Initialize( ) in the app task's main. Any insights?

     

  • Any updates on this issue?

  • Sorry for the delayed response as I was out of office for the past two weeks.

    What's your AppTask priority? 

    Can you add RF observable(LNA and PA) for debugging? and use logic analyzer to check the LNA, PA and SPI pins activities during connection.

    http://dev.ti.com/tirex/content/simplelink_cc2640r2_sdk_3_20_00_21/docs/blestack/ble_user_guide/html/ble-stack-3.x-guide/debugging-index.html#debugging-rf-output

    Also can you check whether you are running out of heap? For more information, please see the documentation below

    http://dev.ti.com/tirex/content/simplelink_cc2640r2_sdk_3_20_00_21/docs/blestack/ble_user_guide/html/ble-stack-3.x-guide/debugging-index.html#debugging-common-heap-issues

  • I have two application tasks on the same priority i.e. 1. The SPI is initialized in one of these tasks.

    I will follow your suggestions as soon as I get some time and come back on it. Currently working on some other stuff.

    Thanks,

    Vinay

  • Hi,

    Please be noted that if you don't provide any comments for this thread within 1 month, the thread will get locked.

    Therefore, if you don't think you will have time to work on it and provide more information within 1 month, then I would like to close this thread and then you can come back to this thread and ask a related question.

  • Close thread due to inactivity.