Questions about SPI

Hello.
nrf5340, in SDK v2.8.0
I'm going to use 3 cs pins for spi communication.
Is there an example to refer to??

And did the setting below go well?

CONFIG_SPI=y
CONFIG_SPI_NRFX=y

--------------------------------------------------------------------------------
&spi1 {
	compatible = "nordic,nrf-spim";
    status = "okay";

	pinctrl-0 = <&spi1_default>;
	pinctrl-1 = <&spi1_sleep>;
	pinctrl-names = "default", "sleep"; 
    
    cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>,  /* CS1 핀 */
               <&gpio0 9 GPIO_ACTIVE_LOW>,  /* CS2 핀 */
               <&gpio0 10 GPIO_ACTIVE_LOW>;  /* CS3 핀 */
               
    slave1: spi-dev1@0 {
        compatible = "spi-device";
        reg = <0>;       /* 슬레이브 1의 ID */
        spi-max-frequency = <8000000>;
    };

    slave2: spi-dev2@1 {
        compatible = "spi-device";
        reg = <1>;       /* 슬레이브 2의 ID */
        spi-max-frequency = <8000000>;
    };

    slave3: spi-dev3@2 {
        compatible = "spi-device";
        reg = <2>;       /* 슬레이브 3의 ID */
        spi-max-frequency = <8000000>;
    };
};


--------------------------------------------------------------------------------
spi1_default: spi1_default {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,        /* SPI SCK 핀 */
					<NRF_PSEL(SPIM_MOSI, 0, 21)>,       /* SPI MOSI 핀 */
					<NRF_PSEL(SPIM_MISO, 0, 22)>;       /* SPI MISO 핀 */
		};
	};

	spi1_sleep: spi1_sleep {
		group1 {
				psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,        /* SPI SCK 핀 */
						<NRF_PSEL(SPIM_MOSI, 0, 21)>,       /* SPI MOSI 핀 */
						<NRF_PSEL(SPIM_MISO, 0, 22)>;       /* SPI MISO 핀 */
				low-power-enable;
		};
	};

  • Hello,

    That looks fine to me. Does it work? How do you differentiate between the three devices in your application? Are either of them working?

    Best regards,

    Edvin

  • as attached above
    I'm doing it like this,
    When building, an error occurs.

    /////////////////////////////////////////////SPI START/////////////////////////////////////////////
    // #define SPI_DEV DT_LABEL(DT_NODELABEL(spi1))
    
    #define CS1_PIN DT_GPIO_PIN_BY_IDX(DT_NODELABEL(spi0), cs_gpios, 0)
    #define CS2_PIN DT_GPIO_PIN_BY_IDX(DT_NODELABEL(spi0), cs_gpios, 1)
    #define CS3_PIN DT_GPIO_PIN_BY_IDX(DT_NODELABEL(spi0), cs_gpios, 2)
    
    static struct spi_config spi_cfg = {
        .frequency = 1000000,  // SPI clock frequency (1 MHz)
        .operation = SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8),
        .slave = 0,            // SPI device 0 (chip-select 1)
        .cs = NULL             // CS pin will be managed manually
    };
    
    // static const struct device *spi_dev;
    // static const struct device *cs_gpio_1;
    // static const struct device *cs_gpio_2;
    // static const struct device *cs_gpio_3;
    
    static struct gpio_dt_spec cs_gpio_1 = GPIO_DT_SPEC_GET(DT_NODELABEL(spi0), CS1_PIN);
    // static struct gpio_dt_spec cs_gpio_2 = GPIO_DT_SPEC_GET(DT_NODELABEL(spi0), CS2_PIN);
    // static struct gpio_dt_spec cs_gpio_3 = GPIO_DT_SPEC_GET(DT_NODELABEL(spi0), CS3_PIN);
    
    void spi_init(void)
    {
    }
    /////////////////////////////////////////////SPI END/////////////////////////////////////////////

  • Hello,

    Please zip your application folder and upload it here. There are still files that will affect how your application is being built that are not uploaded yet. If you zip the entire application, I know that the files are all from the same point in time. 

    Best regards,

    Edvin

Related