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 Ubaid

    This should indeed be possible. In order to have one SPI(M) instance handle multiple slaves, you should make multiple structs with different CS pin inits that can be called from the SPI write/read functions so you easily can switch between what devices you'd like to handle.

    Best regards,

    Simon

  • Hello  ,

    Thanks for the info, 

    you should make multiple structs with different CS pin inits that can be called from the SPI write/read functions so you easily can switch between what devices you'd like to handle.

    I am more interested in the dts/overlay file's way of using multiple cs:

    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <41>;
    	mosi-pin = <40>;
    	miso-pin = <4>;
    	cs-gpios = <&gpio0 22 0xff>,<&gpio0 23 0xff>;
    };
     

    As in this code snippet, "cs-gpios" node is assigned to multiple cs pins,
    I want to know how this is handled in the code to switch between slaves.

    Kindly suggest.

    Thanks,

Reply
  • Hello  ,

    Thanks for the info, 

    you should make multiple structs with different CS pin inits that can be called from the SPI write/read functions so you easily can switch between what devices you'd like to handle.

    I am more interested in the dts/overlay file's way of using multiple cs:

    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <41>;
    	mosi-pin = <40>;
    	miso-pin = <4>;
    	cs-gpios = <&gpio0 22 0xff>,<&gpio0 23 0xff>;
    };
     

    As in this code snippet, "cs-gpios" node is assigned to multiple cs pins,
    I want to know how this is handled in the code to switch between slaves.

    Kindly suggest.

    Thanks,

Children
No Data
Related