This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF9160 SPI Clock Frequency Config

1. Using Zephyr, trying to config SPI_3 of nrf9160 more than 1MHz for flash interface.

2. Ending up in faults.

3. We need to configure SPI_3 as master with freq > 2MHz

4.  could you help us out (or) provide an alternate

5. Code snippet as below

""

#define EFLASH_SPI_FREQ 2000000 // 2MHz

eFlash_spi_cfg.operation = ( SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER);// | SPI_MODE_CPOL | SPI_MODE_CPHA );
eFlash_spi_cfg.frequency = EFLASH_SPI_FREQ;
eFlash_spi_cfg.slave = 0;
eFlash_spi_cfg.cs = &eFlash_spi_css;

spi_transceive(eFlash_spi_dev, &eFlash_spi_cfg, &eFlash_tx, &eFlash_rx);

""

Advance Thanks

[email protected]

Parents
  • Hi again, Nikhil!

    I had a talk with Lorenzo about this issue. Let's try to figure this out! Firstly, what does your Device Tree overlay file look like? It's important that the clock-frequency parameter is large enough. I understood that you where wondering where the clock is sourced from as well and that would be the HFCLK.

    Could you try to test with this SPI sample? I just tried it and achieved 4MHz frequency without any issues.

    If you get any errors or similar please share your build folder and the error messages.

    Best regards,
    Carl Richard

  • Hi Carl and Team,
    I have below design approach to interface NOR-Flash on SPI3 which supports up to 33MHz.
    Could you verify this and give suitable advice. 

    ""

    // eFLASH SPI:
    #define EFLASH_SPI_CH "SPI_3" // SPI channel-3
    #define EFLASH_SPI_FREQ 400000 //400000 //1000000 // 1MHz

    // eFLASH SPI's CS pin:
    #define EFLASH_SPICS_NODE DT_ALIAS(flashspics)
    #define EFLASH_SPICS DT_GPIO_LABEL(EFLASH_SPICS_NODE, gpios)
    #define EFLASH_SPICS_PIN DT_GPIO_PIN(EFLASH_SPICS_NODE, gpios) // pin-15
    #define EFLASH_SPICS_FLAGS DT_GPIO_FLAGS(EFLASH_SPICS_NODE, gpios)

    static struct spi_cs_control eFlash_spi_css;
    static struct device* eFlash_spi_dev;
    static struct spi_config eFlash_spi_cfg;

    static uint8_t eFlash_tx_buffer[261];
    static struct spi_buf eFlash_tx_buf = {
    .buf = eFlash_tx_buffer,
    .len = 1,
    };
    static struct spi_buf_set eFlash_tx = {
    .buffers = &eFlash_tx_buf,
    .count = 1,
    };

    static uint8_t eFlash_rx_buffer[261];
    static struct spi_buf eFlash_rx_buf = {
    .buf = eFlash_rx_buffer,
    .len = 1,
    };
    static struct spi_buf_set eFlash_rx = {
    .buffers = &eFlash_rx_buf,
    .count = 1,
    };

    uint8_t eFlash_spiInit(void) {
    eFlash_spi_css.gpio_dev = device_get_binding(EFLASH_SPICS);
    eFlash_spi_css.gpio_pin = EFLASH_SPICS_PIN;
    eFlash_spi_css.delay = 1; // 1msec
    eFlash_spi_css.gpio_dt_flags = GPIO_ACTIVE_LOW;

    eFlash_spi_dev = device_get_binding(EFLASH_SPI_CH);
    if (eFlash_spi_dev == NULL) {
    //printk("Could not get %s device\n", EFLASH_SPI_CH);
    return 1; // error, SPI device binding error
    }

    eFlash_spi_cfg.operation = (SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER);// | SPI_MODE_CPOL | SPI_MODE_CPHA );
    eFlash_spi_cfg.frequency = EFLASH_SPI_FREQ;
    eFlash_spi_cfg.slave = 0;
    eFlash_spi_cfg.cs = &eFlash_spi_css;

    return 0; // success, no error configuring SPI parameters
    }

    uint8_t eFlash_spiTxRx(void) {
    int32_t error;
    error = spi_transceive(eFlash_spi_dev, &eFlash_spi_cfg, &eFlash_tx, &eFlash_rx);
    if (error != 0) {
    //printk("spi_transceive error: %d\n", error);
    return 1; // error, SPI transceive error
    }
    else {
    return 0; // success transceive data on SPI
    }
    }

    ""

  • Hello again!

    It's challenging to review code like this, but from what I can see it looks okay to me. Isn't it working? How is your device tree overlay configured?

    Note that the nRF9160 supports a maximum of 8MHz over SPI.

    Best regards,
    Carl Richard

Reply Children
No Data
Related