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.

CC2640R2F: problem with simultaneous operation of spi and bluetooth

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2640

Hello! I have a problem with operation of SPI on cc2640r2f.

After powering my device is able to operate as should (reacts on buttons, flashes leds and send data over SPI bus). When I trying to set connection with smartphone, cc2640 freezes, don’t reacts on buttons pressing, and I cannot connect from smartphone.

Basic project – Project Zero.

While debugging I could see that undesiradle behavior occurs when I try to do SPI_init() and SPI_open(). when these functions are commented (i.e. SPI is disabled) it is possible to set connection between smartphone and cc2640.

This https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/518760 , this https://e2e.ti.com/support/embedded/tirtos/f/355/t/585359?RTOS-LAUNCHXL-CC2650-Trying-to-Configure-SPI-with-the-CC2650-LAUNCHXL and this https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/612208?CC2640R2F-can-t-open-SPI did not helped me.

SPI initialization code is:

 

SPI_Handle     spi;

SPI_Params     spiParams;

SPI_Transaction spiTransaction;

uint8_t       ( * transmitBuffer)[14];

uint8_t         receiveBuffer[14];

bool           transferOK;

spiParams.dataSize = 8;       // 8-bit data size

SPI_init();

SPI_Params_init(&spiParams);

spi = SPI_open(Board_SPI0, &spiParams);

  • Hello Yura,

    Can you provide some more information?

    Where are you running this init code?
    Have you modified the board files or CC2640_LAUNCHXL files?

    Regards,
    AB
  • Hello, AB, thank you for your interest!

    I am trying to init spi inside main function, before BIOS_start();.
    Earlier I was trying to run code for SPI initialization just before data tranfering, but it did not worked

    int main()
    {

    /* Register Application callback to trap asserts raised in the Stack */
    RegisterAssertCback(AssertHandler);

    PIN_init(BoardGpioInitTable);

    PIN_init(SMPinTable);
    PIN_init(ledPinTable);
    PIN_init(ButtonTable);
    PIN_init(BuzTable);
    ADC_init();


    SPI_Handle spi;
    SPI_Params spiParams;
    SPI_Transaction spiTransaction;
    uint8_t ( * transmitBuffer)[14];
    uint8_t receiveBuffer[14];
    bool transferOK;
    spiParams.dataSize = 8; // 8-bit data size
    SPI_init();
    SPI_Params_init(&spiParams); // Initialize SPI parameters
    spi = SPI_open(Board_SPI0, &spiParams);


    my code;

    }


    I configured BoardGpioInitTable from ProjectZero in CC2640R2_LAUNCHXL.c. I commented not used pins and left SPI pins

    const PIN_Config BoardGpioInitTable[] = {

    // CC2640R2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
    // CC2640R2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
    // CC2640R2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
    // CC2640R2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */
    // 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_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */

    PIN_TERMINATE
    };
  • Hello,

    I would recommend to only do SPI_init on the main(), and the rest of the SPI operations on a actual TI RTOS task. The reason for this is because when you do any type of peripheral open (ADC_open, GPIO_open, SPI_Open, etc..) you are creating different TI RTOS objects (Semaphores, Queues, etc..) and these cannot be created unless the BIOS_start runs.

    Your code looks good, to make it work just write it on the actual project zero task, or create a separate task just for SPI operation (My recommendation).

    Regards,
    AB
  • Hello, AB!
    Opening SPI in actual task and calling SPI transferring functions does not influence on the device behavior. This is the code under consideration

    int main()
    {

    My code
    /* Initialize ICall module */
    ICall_init();

    /* Start tasks of external images - Priority 5 */
    ICall_createRemoteTasks();

    /* Kick off profile - Priority 3 */
    GAPRole_createTask();

    // controller task. SPI is called here
    Controller_createTask();

    TimeCtrl_createTask();

    ProjectZero_createTask();

    /* enable interrupts and start SYS/BIOS */
    BIOS_start();

    return 0;
    }

    Part of controller task code following

    void Controller_createTask(void)
    {
    Task_Params CtrltaskParams;

    // Configure task
    Task_Params_init(&CtrltaskParams);
    CtrltaskParams.stack = CtrlprzTaskStack;
    CtrltaskParams.stackSize = TASK_STACK_SIZE;
    CtrltaskParams.priority = TASK_PRIORITY;
    Task_construct(&CtrlprzTask, Controller_taskFxn, &CtrltaskParams, NULL);
    // System_printf("ctrl task started.\n");
    }

    void Controller_taskFxn (UArg a0, UArg a1)
    {
    Code, preliminary setup of the device
    while (1)
    {
    My code
    SPI_write();
    My code
    } // end of while (1)
    } // end of Controller_taskFxn
    void SPI_write (void)
    {
    SPI_Handle spi;
    SPI_Params spiParams;
    SPI_Transaction spiTransaction;
    uint8_t ( * transmitBuffer)[14];
    uint8_t receiveBuffer[14];
    bool transferOK;
    spiParams.dataSize = 8; // 8-bit data size
    SPI_Params_init(&spiParams); // Initialize SPI parameters
    spi = SPI_open(Board_SPI0, &spiParams); // if (spi == NULL)
    // {
    // while (1); // SPI_open() failed
    // }

    PIN_setOutputValue(ledPinHandle, CS, 0); //CS = 0

    transmitBuffer = &data_to_send;
    spiTransaction.count = 1;
    spiTransaction.txBuf = transmitBuffer;
    spiTransaction.rxBuf = receiveBuffer;

    transferOK = SPI_transfer(spi, &spiTransaction);
    if (!transferOK)
    {
    // Error in SPI or transfer already in progress.
    }

    PIN_setOutputValue(ledPinHandle, CS, 1); //CS = 1


    } // end of SPI_write()


    I will try to create one more task for SPI and answer.
  • Hello Yura,

    Have you been able to get this working?
    did you create a separate task since last post?

    Regards,
    AB
  • Hello!

    Your advice did not help.

    I think the reason was too big size of the hex file.

    But I can not chek this now, becouse we do not need SPI on our project any more.

    Thank you a lot for your help!