nRF5340 1-wire EEPROM

Hello,

I have nrf5340dk and AT21CS01-STUM10-T module. This is EEPROM module. I want to communicate with it by 1-wire. 
The problem is that I don't know how to do it. I looked through examples in SDK and DevZone but didn't find anything helpful for me. I found an example with 1-wire in the SDK (v2.8.0), but there is very short code in it and there is no overlay for Nordic board. I see that this example uses the w1 driver. When I looked at the w1.h file, I saw functions for writing and reading, but I didn't try them because I don't know how .overlay file for 1-wire should look like.

Can you help me with it ?

Best Regards

Parents Reply Children
  • Hi,

    Thanks for your reply.

    I tried to use 1w library with my module, but it didn't work.

    Then i found this site
    AT21CS01 | Microchip Technology
    and I downloaded this code:
    https://ww1.microchip.com/downloads/aemDocuments/documents/MPD/ApplicationNotes/AppnoteSourceCode/AN3304_Source_Code_V1.0.0.X.zip

    I ported this code (only low-level.h, low-level.c, operations.h, operations.c files) to ESP32 and it works.
    Then I ported this code to nordic (for now nRF52840dk). But I have problem - my code read only "0xFF" value when EEPROM is connected (or 0x00 when pin is connected to GND). I was checking with Logic Analyzer how single wire signal looks and it is similar to the one generated by ESP (times are also similar).
    I think this problem is caused by pin configuration.

    This is my .overlay file

    / {
    	m_pin {
    		compatible = "gpio-leds";
    		m_pin0: m_pin_0 {
    			gpios = <&gpio0 29 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
    			label = "M_PIN";
    		};
    	};
    
    	aliases {
    		mpin = &m_pin0;
    	};
    };


    and I have this lines in my code:

    int ret;
    
    if (!gpio_is_ready_dt(&mypin)) {
    	return -1;
    }
    
    ret = gpio_pin_configure_dt(&mypin, GPIO_INPUT | GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_PULL_UP);
    if (ret < 0) {
    	return -1;
    }



    I also tried to switching pin_configure_dt depending on writing and reading from module but it didn't help.

    // before writing to module
    //ret = gpio_pin_configure_dt(&mypin, GPIO_INPUT | GPIO_OPEN_DRAIN | GPIO_PULL_UP); // I had an error with this line
    ret = gpio_pin_configure_dt(&mypin, GPIO_OUTPUT | GPIO_INPUT | GPIO_OPEN_DRAIN | GPIO_PULL_UP);
    //ret = gpio_pin_configure_dt(&mypin, GPIO_INPUT); // I also tried this - but then in .overlay file was this line: 'gpios = <&gpio0 29 (GPIO_PULL_UP)>;'
    if (ret < 0) {
        printk("\n\tERROR: configure INPUT\n");
    }
    
    
    
    // before reading from module
    ret = gpio_pin_configure_dt(&mypin, GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_PULL_UP);
    if (ret < 0) {
        printk("\n\tERROR: configure OUTPUT\n");
    }
    





    Can you help me with it ?

    Best Regards

  • Hi,

     

    Reading a pin is either '0' or '1'. You will not get a serialized data output without fully bit-banging your chosen protocol. I would recommend that you look into the former w1-scanner and try to get that running instead of just reading a gpio input.

     

    Kind regards,

    Håkon

  • Hi,

    But problem is that w1-scanner doesn't work with my module.

    With the configuration you wrote above I have this output (when my module is connected):
    [00:00:00.251,220] <inf> main: Number of devices found on bus: 0
    and this when nothng is connected to port P1.08:
    [00:00:00.254,791] <err> w1_serial: tx_rx_error reset_present
    [00:00:00.254,791] <inf> main: Number of devices found on bus: -5

    Second thing is that I want to read and write data, and this functionality is not presented in this sample.

    I have the above code which I tested with ESP and it works with my EEPROM module, so I would like to implement this code on nrf but I have problem that nrf is not reading data from EEPROM.


    Can you help me with it ?

    Best Regards

Related