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

NRF9160 - multiple SPI slave

Hi, 

I cant find an example / documentation for controlling multiple SPI slaves (by using different CS pins).

can someone please direct me? 

  • Hi,

    It doesn't look like it should be a problem to control multiple CS pins with the Zephyr SPI API. You can create more instances of the spi_cs_control structure, one for each slave, then make sure to pass the correct CS structure when you call the spi_read/write/transceive functions.

  • I have tried both spi3 and spi2 in separate examples which work OK.  However, when I put both of them in the same example I get a run-time error "SPI device SPI_2 not found"

    I'm using nrf9160-DK with this overlay file and building with west:

    ```

    &spi2 {
    mosi-pin = <31>;
    compatible = "nordic,nrf-spim";
    led_strip: ws2812@0 {
    compatible = "worldsemi,ws2812-spi";
    label = "WS2812";

    /* SPI */
    reg = <0>; /* necessary for SPI bindings */
    spi-max-frequency = <4000000>;

    /* WS2812 */
    chain-length = <1>; /* arbitrary; change at will */
    spi-one-frame = <0x70>;
    spi-zero-frame = <0x40>;
    };
    };

    &uart2 {
    status = "disabled";
    };

    / {
    aliases {
    led-strip = &led_strip;
    };
    };

    &spi3 {
    status = "okay";
    sck-pin = <11>;
    mosi-pin = <10>;
    miso-pin = <12>;
    cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;

    bme280@13 {
    compatible = "bosch,bme280";
    reg = <0x00>;
    spi-max-frequency = <4000000>;
    label = "BME280";
    };
    };

    &uart3 {
    status = "disabled";
    };

    ```

    In my prj.conf I have:

    ```

    ## sensors
    CONFIG_SENSOR=y
    CONFIG_SPI=y
    CONFIG_I2C=n
    CONFIG_BME280=y


    ##LEDs
    CONFIG_LED_STRIP=y
    CONFIG_WS2812_STRIP=y

    ```

    I went back to the single SPI examples and found that I can't use either SPI1 or 2 - same error.

    Any suggestions please?

Related