w25q16jv interfacing with nRF 52833 board

I am trying to interface winbond flash with the 33 board using ncs and VS code , I am able to get the code to compile and not receiving any errors , it is working and no matter what i send i am getting FF as a response

I have referred to Case ID: 261312

But As mentioned in the first link provided to change the .dts file . I cannot put in any pin configurations , if i do it is showing me a assert error for not having pin control in it , even when i try changing the pin numbers in the .overlay file I am getting the same issues . 

/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <sys/printk.h>
#include <device.h>
#include <drivers/spi.h>
#include <hal/nrf_gpio.h>
#define MY_SPI DT_NODELABEL(spi3)
#define CS_PIN 16
#define SPI_MODE_CPOL 0
#define SPI_MODE_CPHA 0

static const struct spi_config spi_cfg = {
	.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
		     SPI_MODE_CPOL | SPI_MODE_CPHA,
	.frequency = 50000000,
	.slave = 1,
	
};

static const struct spi_cs_control cs_pin = {
	.gpio_pin=16,

};

const struct spi_dt_spec *spi_dev = DEVICE_DT_GET(MY_SPI);

static void spi_init(void)
{

if (!device_is_ready(spi_dev)) {
       	printk("Could not get device\n");
}
}

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);
		k_busy_wait(100000);
		// 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);
			//k_busy_wait(1000);
	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]);
	}
		rx_buffer[0]=0x00;
		tx_buffer[0]=0x00;
		// b1=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]);
	}
		rx_buffer[0]=0x00;
		tx_buffer[0]=0x00;
		// b2=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]);
	}
		rx_buffer[0]=0x00;
		tx_buffer[0]=0x00;
		// b3=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]);
	}
		// GPIO_SetBits(SPI_CS_MS_DEMO_PIN);
		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));
	}
}
 

&spi3 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    //sck-pin = <11>;
   // mosi-pin = <10>;
    //miso-pin = <12>;
};
this works and only gives me read values as FF

Parents
  • Hi

    Can you upload the error message you're seeing on your end? It doesn't seem like you have "named" the device as you should in the overlay file, with label, JEDEC-ID, size and max frequency. Please also note that pin P0.10 that you're using as the MOSI pin, is by default configured as an NFC pin by default, and you will have to add the following config to your prj.conf file to use this as a normal GPIO: CONFIG_NFCT_PINS_AS_GPIOS. Additionally, if you're working on an nRF52833 DK, there are some HW changes necessary to use P0.09 and P0.10 as GPIOs. This is described in our DK user guide.

    Best regards,

    Simon

  • Hi Simon , I am using the default pins for spi ,i.e. SPI default which is 23-22-21 .

    PIN 10 was  used in that example hence I have commented them 

    I have tried the spi loop back and it is working properly.

    Yes I haven't named the device , I am a little confused in what to mention in my overlay file . could you help me with that?

  • HI Simon I have connected a logic analyzer and I don't see anything on my CS pin being activated , I have tried using CS-GPIO in the DTS and I also tied the spi_cs_control .

  • Hi I can now get my cs pin to work and I am Unable to get any response from the flash , I tried implementing the flash with arduino and i can read the values stored in it , As per the data sheet i am trying to send 90h and then 000000h , where am i going wrong

    #include <zephyr.h>
    #include <sys/printk.h>
    #include <device.h>
    #include <drivers/spi.h>
    #include <hal/nrf_gpio.h>
    #include <kernel.h>
    #define SPI_MODE_CPOL 0
    #define MY_SPI DT_NODELABEL(spi3)
    
      struct spi_cs_control spim_cs_one = { 
                                .gpio_dev = NULL,
        						.gpio_pin = 20,
        						.gpio_dt_flags = GPIO_ACTIVE_LOW,
        						.delay = 0,
      };
    
    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,
    	.cs= &spim_cs_one
    };
    
    struct device * spi_dev;
    
    static void spi_init(void)
    {
    	spim_cs_one.gpio_dev = device_get_binding("GPIO_0");
    	
    	const char* const spiName = "SPI_3";
    	spi_dev = device_get_binding(spiName);
    
    	if (spi_dev == NULL) {
    		printk("Could not get %s device\n", spiName);
    		return;
    	}
    }
    
    void spi_test_send(void)
    {
    	int err;
    	static uint8_t tx_buffer[4]={
    		0x90,
    		0x00,
    		0x00,
    		0x00
    	};
    	static uint8_t rx_buffer[2];
    
    	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
    	};
    
    	err = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);
    	if (err) {
    		printk("SPI error: %d\n", err);
    	} else {
    		/* Connect MISO to MOSI for loopback */
    		printk("TX sent: %x\n", tx_buffer[0]);
    		for(int i=0;i<2;i++){
    		printk("RX recv: %x\n", rx_buffer[0]);
    		}
    	}	
    }
    
    void main(void)
    {
    	printk("SPIM Example\n");
    	spi_init();
    
    	while (1) {
    		spi_test_send();
    		k_sleep(K_SECONDS(2));
    	}
    }

Reply
  • Hi I can now get my cs pin to work and I am Unable to get any response from the flash , I tried implementing the flash with arduino and i can read the values stored in it , As per the data sheet i am trying to send 90h and then 000000h , where am i going wrong

    #include <zephyr.h>
    #include <sys/printk.h>
    #include <device.h>
    #include <drivers/spi.h>
    #include <hal/nrf_gpio.h>
    #include <kernel.h>
    #define SPI_MODE_CPOL 0
    #define MY_SPI DT_NODELABEL(spi3)
    
      struct spi_cs_control spim_cs_one = { 
                                .gpio_dev = NULL,
        						.gpio_pin = 20,
        						.gpio_dt_flags = GPIO_ACTIVE_LOW,
        						.delay = 0,
      };
    
    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,
    	.cs= &spim_cs_one
    };
    
    struct device * spi_dev;
    
    static void spi_init(void)
    {
    	spim_cs_one.gpio_dev = device_get_binding("GPIO_0");
    	
    	const char* const spiName = "SPI_3";
    	spi_dev = device_get_binding(spiName);
    
    	if (spi_dev == NULL) {
    		printk("Could not get %s device\n", spiName);
    		return;
    	}
    }
    
    void spi_test_send(void)
    {
    	int err;
    	static uint8_t tx_buffer[4]={
    		0x90,
    		0x00,
    		0x00,
    		0x00
    	};
    	static uint8_t rx_buffer[2];
    
    	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
    	};
    
    	err = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);
    	if (err) {
    		printk("SPI error: %d\n", err);
    	} else {
    		/* Connect MISO to MOSI for loopback */
    		printk("TX sent: %x\n", tx_buffer[0]);
    		for(int i=0;i<2;i++){
    		printk("RX recv: %x\n", rx_buffer[0]);
    		}
    	}	
    }
    
    void main(void)
    {
    	printk("SPIM Example\n");
    	spi_init();
    
    	while (1) {
    		spi_test_send();
    		k_sleep(K_SECONDS(2));
    	}
    }

Children
No Data
Related