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.

CC2650 SPI Crashes Project

Other Parts Discussed in Thread: CC2650, ADS1291

Hi there,

i am using the CC2650 Launchpad with the Sensortag Project.

I made my custom device file and i can program my device with SPI and get the values from it.

After a few seconds the MCU crashes and stops.

The reason is because of the spi read function. My data is ready at a 500Hz frequency and i get an interrupt to get the value.

Once the interrupt is in action, it calls my int function and i send the spi read command to get the value:

Set_ADS1291_Chip_Enable();

success= bspSpiRead(SPI_Tx_buf, 4);

Clear_ADS1291_Chip_Enable();

I have commented the "success= bspSpiRead(SPI_Tx_buf, 4);" out and the project didnt crash anymore.

So is there anything wrong with my SPI? Is there anything on sensortag project that is incompatible with it?

On the oscilloscope i can see that the 4 SPI clock blocks are sent out and the ADS1291 device is sending the value.

The only thing strange is that returned "success" value is "failed", why is it failing? Is this the reason why is crashing?

The MCU is only advertising and not connected to any device at this point.

Any idea? 

  • Hi Michael,

    If you pause your debugger when the device crashes can you gain any information about the crash? What exception is it caught in? Anything look with with the heap or registers?
  • Also, just to check, are you opening the SPI port with bspSpiOpen? Can you verify that the spiHandle is non NULL at init time?
  • Hi Sean2,

    i am using CCS Cloud and yes i am opening the SPI port with bspSpiOpen.

    I went in that function and checked that that spiHandle is non NULL:

    /* Attempt to open SPI. */
    spiHandle = SPI_open(Board_SPI0, &spiParams);

    if (spiHandle == NULL)
    {
    Task_exit();
    }

    So far so good, because i can see it is sending and receiving correctly. 

    Ho can i checked while debbuging where the device is hanging on CCS Cloud? Or how do i checked the registers?

  • Hi Sean2,

    i took a picture from the SPI and i found out that only when retreaving the ADC Value the CS comes earlier as expected:

    After 100 times doing this the CC2650 crashes.

    Here is what i am doing:

    uint8_t SPI_Tx_buf[4];

    SPI_Tx_buf[0]=0;
    SPI_Tx_buf[1]=0;
    SPI_Tx_buf[2]=0;
    SPI_Tx_buf[3]=0;

    Set_ADS1291_Chip_Enable();

    success= bspSpiRead(SPI_Tx_buf, 4);

    Clear_ADS1291_Chip_Enable();

    Any idea?

  • I think i found the reason for the crash.

    First of all i did some worked around with the SPI and instead of 1MHz on SCLK i speed it up a little to 12MHz. Now i can get the proper ADS1291 value from he IC.

    I disable BLE advertising and the SPI was running forever and i always got the ADS1291 value without crashing.

    Now when i enabled the advertising and the SPI to get the ADS1291 values, the MCU runs for a few cycles and crashes afterwards.

    I thought that the Stack is in charge for the advertising and the M3 runs independently.

    How can i run my program without crashing? 

    Do i have to run a clock task to get the ADS1291 value or can i use the Interrupt pin as i did to do this?

  • So i think the problem is the SPI transfermode. I am using the blocking mode without a task and thats causing the problem i think.

    On the SPI.h i found this:

    typedef enum SPI_TransferMode {
    /*!
    * SPI_transfer() blocks execution. This mode can only be used when called
    * within a Task context
    */
    SPI_MODE_BLOCKING,
    /*!
    * SPI_transfer() does not block code execution and will call a
    * ::SPI_CallbackFxn. This mode can be used in a Task, Swi, or Hwi context.
    */
    SPI_MODE_CALLBACK
    } SPI_TransferMode;

    So as far as i understood, i cant use the SPI_MODE_BLOCKING without using a task function, otherwise the device wont work or crash.

    So in my case, when using SPI transfer when a interrupt occurs, i have to use SPI_MODE_CALLBACK.

    My question is now how do i define a SPI Callbackfunction?

    if (spiHandle == NULL)
    {
    /* Configure SPI as master, 1 mHz bit rate*/
    SPI_Params_init(&spiParams);
    spiParams.bitRate = 12000000;
    spiParams.mode = SPI_MASTER;
    spiParams.transferMode = SPI_MODE_CALLBACK;//SPI_MODE_BLOCKING;
    spiParams.SPI_CallbackFxn = ?;  <---------------------------------------------------------------------------Here

    /* Attempt to open SPI. */
    spiHandle = SPI_open(Board_SPI0, &spiParams);

    if (spiHandle == NULL)
    {
    Task_exit();
    }
    }

    How do i define SPI_CallbackFxn? 

    spiParams.SPI_CallbackFxn = SPI_CALLFunction(); ??

    Thanks 

  • I fixed the problem!

    It was the blocking SPI mode!

    So i change to callback mode and declared a function "Spi_Int_Callback"

    /* Configure SPI as master, 1 mHz bit rate*/
    SPI_Params_init(&spiParams);
    spiParams.bitRate = 12000000;
    spiParams.mode = SPI_MASTER;
    spiParams.transferMode = SPI_MODE_CALLBACK;//SPI_MODE_BLOCKING;
    spiParams.transferCallbackFxn = Spi_Int_Callback;


    On bsp_spi.h file i declared the function:

    extern void Spi_Int_Callback(SPI_Handle handle, SPI_Transaction *objTransaction);

    and on bsp_spi.c i used this function to get the callback when the SPI has finish to send/receive the data:

    static void Spi_Int_Callback(SPI_Handle handle, SPI_Transaction *objTransaction)
    {

    ADS1291_SPI_DRY();

    }