Handling multiple slaves on single spi master channel

Hi, 

The spi_config structure zephyr provides is as below:

	struct spi_config
	{
		uint32_t frequency;
		uint16_t operation;
		uint16_t slave;

		const struct spi_cs_control *cs;
	};


Wherein cs is initialized to the chip select pin.

In my project I have a requirement to handle 2 slaves which are exactly the same.

Herein, how can I manage 2 instances of, same slaves

And do I need to get multiple device bindings for the same spi channel..?

Thanks,

Ubaid

Parents
  • Hi

    For SPI devices, "@0 or @1" refers to the position of the chip select pin in the cs-gpios configuration. As you can see in the config below from the Thingy91.dts file, the SPI devices are defined to use one CS pin each.

    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <3>;
    	mosi-pin = <4>;
    	miso-pin = <5>;
    	cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>, <&gpio0 7 GPIO_ACTIVE_LOW>;
    
    	adxl362@0 {
    		compatible = "adi,adxl362";
    		label = "ADXL362";
    		spi-max-frequency = <8000000>;
    		reg = <0>;
    		int1-gpios = <&gpio0 9 0>;
    	};
    
    	adxl372@1 {
    		compatible = "adi,adxl372";
    		label = "ADXL372";
    		spi-max-frequency = <8000000>;
    		reg = <1>;
    		int1-gpios = <&gpio0 6 0>;
    	};
    };

    Best regards,

    Simon

  • Hello ,

    Thank you for the info,
    Noted on the dts syntax for multiple slaves.

    Kindly suggest how this can be handled in code, if i want to call "SPI_Write()" on:

    1. slave one <&gpio0 8 GPIO_ACTIVE_LOW>

    2. slave two <&gpio0 7 GPIO_ACTIVE_LOW>

    What would the code syntax look like..?

    How would I configure spi_config..?

    and how would I call  "SPI_Write()" on each slave.

    Thanks,

Reply Children
No Data
Related