This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Weird SPI timings when using Zephyr SPI driver

I've tried sending ASCII "Hello world" over SPI with various data rates. Somehow clock signal given by SPI is not continuous. This discontinuouty differs with clock frequency. Here it's the screenshots of the logic analyzer with SPI frequencies in order 400KHz, 1 MHz, 2 MHz, 8 MHz, 16 MHz.

  • Hi,

    1) What device are you using? nRF51, nRF52832, nRF52840, nRF5340, nRF9160, etc?

    2) Do you have some code snippets or simple example code that you used to test this, that you can share?

    3) What version of nRF Connect SDK(NCS) did you use?

  • Hi

    1) NRF52840 (PCA10059 Dongle)

    2) 

    const struct device *spi_device = device_get_binding(DT_LABEL(SPI));
    if(spi_device == NULL)
    {
        while(1)
        {
            gpio_pin_set(dev1, PIN1, (int)led_is_on);
            led_is_on = !led_is_on;
            k_msleep(100);
        }
    }
    
    struct spi_cs_control cs_control;
    cs_control.gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
    cs_control.delay = 1;
    cs_control.gpio_pin = 13;
    cs_control.gpio_dt_flags = GPIO_ACTIVE_LOW;
    
    struct spi_config config;
    config.frequency = 16000000U;
    config.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER;
    config.slave = 0;
    config.cs = &cs_control;
    
    struct spi_buf spi_tx_buf;
    spi_tx_buf.buf = spi_tx_message;
    spi_tx_buf.len = strlen(spi_tx_message);
    
    struct spi_buf_set spi_tx_buf_set;
    spi_tx_buf_set.buffers = &spi_tx_buf;
    spi_tx_buf_set.count = 1;
    
    gpio_pin_set(dev0, PIN0, 0);
    gpio_pin_set(dev1, PIN1, 0);
    
    while(1)
    {
        int ret_func = spi_write(spi_device, &config, &spi_tx_buf_set);
        if(ret_func == 0)
        {
            gpio_pin_set(dev0, PIN0, (int)led_is_on);
        }
        else
        {
            gpio_pin_set(dev1, PIN1, (int)led_is_on);
        }
        led_is_on = !led_is_on;
        k_msleep(SLEEP_TIME_MS);
    }

    3) The latest release version which is 1.7.0

  • I was not able to reproduce this. I tested on a nRF52840DK.

    Here is the code I used:
    2465.spi.zip

  • When I used SPIM driver instead of SPI, time intervals between bytes are disappeared. 

Related