SPI4 with multiple CS

I have an nRF5340 and need to use the

spi4
device for an SPI bus with multiple devices on it. Each, of course, has a CS pin.

I have to use spi4 because I have uart0, uart1, i2c2, and i2c3 (and there is no "4" device for either UART or I2C). I don't necessarily care about the > 8MHz high-speed capabilities of SPI4, I just need it to act like a regular SPI device with multiple CS pins.

It's rather unclear from the documentation and other posts on this forum how to configure this properly. It appears there's a hardware CS pin (P0.11), which suggests that only a single device can be used (one hardware CS pin means 1 device)? Is it possible to disregard that hardware pin though, and instead use multiple GPIOs for CS pins, like so:

&spi4 {
	status = "okay";
	pinctrl-0 = <&spi0_default>;
	pinctrl-1 = <&spi0_sleep>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>, // 0
	<&gpio0 30 GPIO_ACTIVE_LOW>, // 1
	<&gpio0 7 GPIO_ACTIVE_LOW>, // 2
	<&gpio1 0 GPIO_ACTIVE_LOW>, // 3
	<&gpio0 26 GPIO_ACTIVE_LOW>, // 4
	<&gpio0 27 GPIO_ACTIVE_LOW>; // 5
	
	...
	
};

If I want to use SPI4 in this way (regular speed, multiple CS/devices), and that's actually possible, how would I configure the PIN_CNF[p].MCUSEL and H0H1 values that are mentioned in the "SPI4" bullet at the top of the nRF5340 pinout page? i.e. what values should they have, and as importantly, how do I set them?

Parents
  • Hi,

    Is it possible to disregard that hardware pin though, and instead use multiple GPIOs for CS pins, like so:

    The SPIM driver in Zephyr does not currently support the HW SS pin, it is set to NOT_CONNECTED. The SW control of CS pin should work the same for SPIM4 as the other instances when used through Zephyr SPI driver.

    how would I configure the PIN_CNF[p].MCUSEL and H0H1 values that are mentioned in the "SPI4" bullet at the top of the nRF5340 pinout page? i.e. what values should they have, and as importantly, how do I set them?

    By default, all pins are assigned to the Application core. If you do not need the 32 MHz mode and dedicated pins, you can leave the MCUSEL field as is and assigned the SPIM pins using the PSEL registers like other instances. The H0H1 values can be configured in the pinctrl in devicetree, e.g. like this.

    Best regards,
    Jørgen

  • Thanks Jørgen. If I did want to use the 32MHz mode though, do I need to do anything with MCUSEL register (it mentions using the "Peripheral option" for this pin, but it's not clear what that is or how to set it)?

    And to clarify, I can use the 32MHz mode with multiple devices on the same bus, correct?

Reply Children
No Data
Related