Error while trying to config SPI in VS code .

HI i am working with the nrf 52833 dk board using  nrf connect and trying to implement SPI ,

#define SPI3_NODE DT_NODELABEL(SPI_3)
static const struct spi_dt_spec* dev_spi = SPI_DT_SPEC_GET(SPI3_NODE,SPI_OP_MODE_MASTER,1);

I am getting this error - identifier "__device_dts_ord_DT_N_NODELABEL_SPI_3_BUS_ORD" is undefined. 

I am new to ncs and zephyr , so what is causing this error?

Parents Reply Children
  • Hi , thank you for your response,

    A little simple doubt I have  ,after reading through the sample , what is the difference in using the CS pin through the 

    spi_cs_control                                          and 
    cs-gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
  • Hi,

    With spi_cs_control you can control a CS line via a GPIO line instead of using the inner CS logic of the controller. 

    The example I linked to is based on an older version of nRF Connect SDK (v1.8.0), so it might be a bit outdated. However, I found an example by another colleague which is based on v2.0.2. It is a bit more complex, but it shows how to use SPI with spi_cs_control: https://github.com/too1/ncs-spi-master-slave-example.

    Best regards,

    Marte

  • Hi , yes this a little complex but still understandable ,

    I have a few question regarding the overlay file 

    1) what is this for 

    reg_my_spi_master: spi-dev-a@0 {
    reg = <0>;

    and 

    2) def-char = <0x00>; is showing me an error saying 

    Property not mentioned in "nordic,nrf-spim"

  • If possible could you help me out in trying to use the 1st sample only , I am trying to implement flash and the only thing I want to try first is getting the manufacture ID.

  • #include <zephyr.h>
    #include <sys/printk.h>
    #include <device.h>
    #include <drivers/spi.h>
    #include <hal/nrf_gpio.h>
    
    #define CS_PIN 16
    
    static const struct spi_config spi_cfg = {
    	.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
    		     SPI_MODE_CPOL | SPI_MODE_CPHA,
    	.frequency = 4000000,
    	.slave = 0,
    };
    
    const struct device * spi_dev;
    
    static void spi_init(void)
    {
    	#define SPI_3 DT_NODELABEL(spi3)
    	const struct device *spi_dev = device_get_binding(DT_LABEL(SPI_3));
    }
    
    void spi_test_send(void)
    {
    	int err;
    	static uint8_t tx_buffer[1];
    	static uint8_t rx_buffer[1];
    
    	const struct spi_buf tx_buf = {
    		.buf = tx_buffer,
    		.len = sizeof(tx_buffer)
    	};
    	const struct spi_buf_set tx = {
    		.buffers = &tx_buf,
    		.count = 1
    	};
    
    	struct spi_buf rx_buf = {
    		.buf = rx_buffer,
    		.len = sizeof(rx_buffer),
    	};
    	const struct spi_buf_set rx = {
    		.buffers = &rx_buf,
    		.count = 1
    	};
    	nrf_gpio_cfg_output(CS_PIN);
    		// GPIO_SetBits(SPI_CS_MS_DEMO_PIN);
    		nrf_gpio_pin_set(CS_PIN);
    		// GPIO_ResetBits(SPI_CS_MS_DEMO_PIN);
    		nrf_gpio_pin_clear(CS_PIN);
    		tx_buffer[0]=0x9F;
    		// SPI_Send_Receive_Data(&a, &a1);
    		err = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);
    	if (err) {
    		printk("SPI error: %d\n", err);
    	}else{
    		printk("TX sent: %x\n", tx_buffer[0]);
    		printk("RX recv: %x\n", rx_buffer[0]);
    	}
    
    		nrf_gpio_pin_set(CS_PIN);
    	
    }
    
    void main(void)
    {
    	printk("SPIM Example\n");
    	spi_init();
    
    	while (1) {
    		spi_test_send();
    		k_sleep(K_SECONDS(1));
    	}
    }

    this is the code i am working with , what changes do you suggest i make 

    I cannot establish a connection only with the spi device .

Related