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

    I still think this is an issue with your devicetree settings, please read our documentation on it thoroughly. I would also recommend trying to do some debugging so we can see what is actually returning error codes.

    In your .dts file, when using an external flash, it should look something like this (SPI instead of QSPI though, since you're using an nRF52833). But the jedec-id, sfdp-bfp, size, etc. needs to match the external flash's datasheet.

    &qspi {
    	status = "okay";
    	pinctrl-0 = <&qspi_default>;
    	pinctrl-1 = <&qspi_sleep>;
    	pinctrl-names = "default", "sleep";
    	mx25r64: mx25r6435f@0 {
    		compatible = "nordic,qspi-nor";
    		reg = <0>;
    		/* MX25R64 supports only pp and pp4io */
    		writeoc = "pp4io";
    		/* MX25R64 supports all readoc options */
    		readoc = "read4io";
    		sck-frequency = <8000000>;
    		label = "MX25R64";
    		jedec-id = [c2 28 17];
    		sfdp-bfp = [
    			e5 20 f1 ff  ff ff ff 03  44 eb 08 6b  08 3b 04 bb
    			ee ff ff ff  ff ff 00 ff  ff ff 00 ff  0c 20 0f 52
    			10 d8 00 ff  23 72 f5 00  82 ed 04 cc  44 83 68 44
    			30 b0 30 b0  f7 c4 d5 5c  00 be 29 ff  f0 d0 ff ff
    		];
    		size = <67108864>;
    		has-dpd;
    		t-enter-dpd = <10000>;
    		t-exit-dpd = <35000>;
    	};
    };

    Best regards,

    Simon

  • Hi Simon , Yes I was not adding anything like this to my DT , I will try this out ,

    I am new to DTs and its functioning, Thank you for being patient  

  • Hi Simon after making the necessary changes in my DT setting i still have not gotten it to work 

    this is my dts spi3 setting

    arduino_spi: &spi3 {
    	status = "okay";
    	cs-gpios = <&gpio0  20 GPIO_ACTIVE_LOW>; /* D10 */
    	pinctrl-0 = <&spi3_default>;
    	pinctrl-1 = <&spi3_sleep>;
    	pinctrl-names = "default", "sleep";
    	w25q16jv: w25q16jv@0 {
    		compatible = "jedec,spi-nor";
    		reg = <0>;
    		spi-max-frequency = <50000000>;
    		label = "w25q16jv";
    		jedec-id = [EF 70 16];
    		size = <16777216>;
    	};
    };

Reply
  • Hi Simon after making the necessary changes in my DT setting i still have not gotten it to work 

    this is my dts spi3 setting

    arduino_spi: &spi3 {
    	status = "okay";
    	cs-gpios = <&gpio0  20 GPIO_ACTIVE_LOW>; /* D10 */
    	pinctrl-0 = <&spi3_default>;
    	pinctrl-1 = <&spi3_sleep>;
    	pinctrl-names = "default", "sleep";
    	w25q16jv: w25q16jv@0 {
    		compatible = "jedec,spi-nor";
    		reg = <0>;
    		spi-max-frequency = <50000000>;
    		label = "w25q16jv";
    		jedec-id = [EF 70 16];
    		size = <16777216>;
    	};
    };

Children
Related