0

I'm trying to connect EEPROM chip 24LC01B to Arduino Nano 328P, write data to it, read and display it in Serial Monitor.

Serial Monitor shows only

Writing... Reading...

I can't figure out what the problem is.

#include <Wire.h>

#define memoryAddr 0x50
byte in=0x00;

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(9600);
}


void loop()
{
  Serial.println("Writing...");
  
  Wire.beginTransmission(0x50); // This is the 24LC01B device address
  Wire.write(0x0);               // Start writing at address 0
  Wire.write("Hell");            // Send 4 bytes
  Wire.endTransmission();       
  delay(100);                    // Without a short delay, the EEPROM is still
                                // writing when you start to write the next block
                                // Feel free to experiment with the delay length
  
  Wire.beginTransmission(0x50);
  Wire.write(0x4);               // Write next four bytes starting at address 4
  Wire.write("o Wo");
  Wire.endTransmission();     
  delay(100);
  

  Wire.beginTransmission(0x50);
  Wire.write(0x8);               // Write last four bytes starting at address 8
  Wire.write("rld!");
  Wire.endTransmission();     
  delay(100);

  Serial.println("Reading...");

  Wire.beginTransmission(0x50); // Now we're going to read it back
  Wire.write(0x0);               // Sending address 0, so it knows where we'll want
  Wire.endTransmission();       // to read from

  Wire.requestFrom(0x50,12);    // Start new transmission and keep reading for 12 bytes
  while(Wire.available())    
  { 
    char c = Wire.read();    // Read a byte and write it out to the Serial port
    Serial.print(c);         
  } 
  Serial.println();

  delay(5000);
}

Here is how I've connected it: https://i.stack.imgur.com/m8EFc.jpg

Andrii
  • 19
  • 2
  • 9
  • Have you checked what endTransmission() return? – Nino Apr 24 '21 at 17:43
  • @Nino, I've changed the last part of the code: `Wire.endTransmission(); int x = Wire.endTransmission(); Serial.println(x, DEC); Serial.println("Done");` and got a value of 2, which should mean "received NACK on transmit of address". I'll try to google it, but I'd be grateful if someone could help figure it out as well. – Andrii Apr 25 '21 at 07:58
  • Call endTransmission only once! – Nino Apr 25 '21 at 10:01
  • @Nino OK, the last part of my code now looks like this. `Serial.println("Reading..."); Wire.beginTransmission(0x50); Wire.write(0x0); int x = Wire.endTransmission(); Serial.println(x, DEC); Serial.println("Done"); delay(5000); }` Am I getting the return value correctly? – Andrii Apr 25 '21 at 10:53
  • This looks right. What are you getting? – Nino Apr 25 '21 at 17:37
  • @Nino I'm receiving 2, which is NACK, I believe. I haven't yet figured out how to proceed with this issue. – Andrii Apr 26 '21 at 18:08

0 Answers0