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

spi on nrf52840_pca10056 dk with zephyr

Hello

I'm trying to get spi to work on nrf52. First tried to use it with adxl372 driver but got nothing on device_binding returns null. Next I tried to create own driver for testing the functionality.

The code I used attached below. I have no clock or mosi signal in oscilloscope. Only chip select signal was responding.

prj.conf

CONFIG_GPIO=y
CONFIG_UART_CONSOLE=y

CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_SPI=y
CONFIG_SPI_NRFX=y
CONFIG_SPI_1=y
CONFIG_SPI_1_NRF_SPI=y

static void spiTest()
{
    struct device *spi = device_get_binding("SPI_1");
    struct device *gpio = device_get_binding(LED_PORT);
    struct spi_cs_control cs;
    struct spi_config cfg;

    gpio_pin_configure(gpio, LED, GPIO_DIR_OUT);

    cs.gpio_dev = gpio;
    cs.gpio_pin = LED;
    cfg.frequency = 2000000;
    cfg.operation = SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8);
    cfg.slave = 0;
    cfg.cs = &cs;

    if(spi == NULL){
        printk("spi not found\n");
        return;
   
    // Write some data
    u8_t data[] = {1,2,3,4};
    struct spi_buf tx_buf = {.buf = data, .len = 4};
    struct spi_buf_set tx_bufs = {.buffers = &tx_buf, .count = 1};
   
     spi_write(spi, &cfg, &tx_bufs);
   
   
}

  • We recommend using the nRF5 SDK when developing with nRF52 devices, and NCS (Zephyr) when developing with the nRF91. What is the reason you ended up using Zephyr?

    Unfortunately, we don't give support for Zephyr running on nRF52840.  

    To use Zephyr samples on the nRF52 series, please follow this guide. More information can be in this link, and as stated in the bottom of the page: "Also if you want to get involved with Zephyr, or simply need help as a user, you can join the Zephyr mailing list or join the #zephyrproject IRC channel."

    Thanks for your understanding.

    Best regards,

    Simon

Related