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.

CC2642R: SPI clock I have configured as 1MHZ but its not generating the proper clock SPI transctions getting slower why?

Part Number: CC2642R

Tool/software:

Dear Team,

I have configured the SPI driver in Code Composer and set a 1MHz clock, but my SPI transactions are slower than expected. I am not able to achieve a 1MHz clock whenever I call the SPI write function in the main while loop.

Here is my code for setting the SPI parameters:

void spi_param_setting(void)
{
SPI_Params_init(&spiParams);
spiParams.frameFormat = SPI_POL0_PHA1;
spiParams.bitRate = 1000000;
spiParams.mode = SPI_MASTER;
spiParams.transferMode =SPI_MODE_CALLBACK;
spiParams.transferCallbackFxn = spicallbackfx;

open_spi();

}


while (1) {
// sleep(time);
// Send_data();

GPIO_write(CONFIG_GPIO_CS, 1); //CS HIGH
//GPIO_write(CONFIG_GPIO_LED_0, 1);
//data[0] = 0x01;
//data[1] = 0x3F;
spi_write_hw(1,data);
// usleep(1);
GPIO_write(CONFIG_GPIO_CS, 0); // CS LOW
// usleep(1);
//GPIO_write(CONFIG_GPIO_LED_0, 0);
//GPIO_write(CONFIG_GPIO_CS, 1);

}

  • Hello Triveni, 

    What version of the SDK are you using and are you building this project from an existing example within the SDK? Can you provide any screen shots or captures of logic analyzer scopes that show the slower SPI transactions?

    How is this function being called?

    Regards, 

    David 

  • Hello David,

    I am using SDK 5_20_00_52, I configured CONFIG_SPI_0, set 4000000 and I called function in main while like this below.

    the problem is I wanted to understand why Spi write is taking 40 to 50 microseconds, and why usleeps are not accurate.

    please find the attached screenshots and scope pictures.

    void spi_param_setting(void)
    {
    SPI_Params_init(&spiParams);
    spiParams.frameFormat = SPI_POL0_PHA1;
    spiParams.bitRate = 4000000;
    spiParams.mode = SPI_MASTER;
    spiParams.transferMode =SPI_MODE_CALLBACK;
    spiParams.transferCallbackFxn = spicallbackfx;

    open_spi();

    }


    void *mainThread(void *arg0)
    {

    /* Call driver init functions */
    GPIO_init();
    SPI_init();
    spi_param_setting();
    Watchdog_init();
    usleep(10);
    WD_param_Setting();
    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    /* Turn on user LED */
    // GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

    while (1) {
    data[0] = 0x03;
    data[1] = 0x3C;
    data[2] = 0x02;
    data[3] = 0x3F;
    GPIO_write(CONFIG_GPIO_CS, 1); //CS HIGH
    spi_write_hw(1,data);
    GPIO_write(CONFIG_GPIO_CS, 0); // CS LOW
    usleep(10);
    GPIO_write(CONFIG_GPIO_CS, 1);
    usleep(10);
    Watchdog_clear(watchdogHandle);

    }
    }

  • Hello Triveni, 

    Can you let me know the timing difference between lines 110 and 112 (this is just to confirm whether the usleep is working correctly)? A more accurate sleep is to use ClockP_usleep(). 

    Can you also provide a screenshot of the spi_write_hw() function? Can you confirm that the clock is 4 MHz on the analyzer?

    Regards, 

    David

  • Hello Devid, I changed the spi transfer mode from SPI_MODE_CALLBACK to SPI_MODE_BLOCKING Data transper happing fast now.

    but still i am getting 1 micro sec delay, I am not understanding from where this delay is getting gerated.

    void *mainThread(void *arg0)
    {

     

        /* Call driver init functions */
        GPIO_init();
        SPI_init();
        spi_param_setting();
        Watchdog_init();
        usleep(5);
        WD_param_Setting();
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
        /* Turn on user LED */
        // GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

     

        while (1) {
            data[0] = 0x07;
            data[1] = 0x3C;
            data[2] = 0x02;
            data[3] = 0x3F;
            data[4] = 0x07;
            data[5] = 0x3C;
            data[6] = 0x02;
            data[7] = 0x3F;
            GPIO_write(CONFIG_GPIO_CS, 1);                                       //CS HIGH
            spi_write_hw(8,data);
            GPIO_write(CONFIG_GPIO_CS, 0);                                       // CS LOW
           // usleep(10);
            GPIO_write(CONFIG_GPIO_CS, 1);
           // usleep(10);
            Watchdog_clear(watchdogHandle);

     

        }
    }
     

  • Hello Triveni, 

    Could you clarify what you mean by a 1 micro second delay, is that a delay occurring before the SPI write to perform the operation? How are you measuring this delay, from GPIO toggles or something else?

    Have you taken a look at the SPIMaster example provided within the SDK to see if this also exists there with the SPI transfer function? 

    What is the expected timing you are looking for from the SPI driver?

    Regards, 

    David