Help with nodeMCU + 24C08 I2C EEPROM
Posted: Wed Nov 23, 2016 12:01 am
Hello there, This is my very first post here.
Using a nodeMCU, I'm trying to read and write an 24C08 I2C EEPROM, seems to be correctly wired, since the Nick Gammon's I2C Scanner detects the device and the neighbor DS1307 connected to the same bus.
The circuit have two 4K7 Ohm pull-up resistors connected to the 3V3 source available at some nodeMCU pins.
The scanner reports 5 devices (see attached image):
0x68, (the DS1307 RTC), and four devices (?) ranging from 0x50 to 0x53, the weird thing is the fact 24C08 EEPROM is supposed to answer only at the 0x50 address (all Address pins connected to GND, also the pin 7, Write Protect is connected to +5V).
I can control and use without problems the RTC; both DS1307 & the 24C08 are connected to the same +5V supply, so the wiring should be correctly cabled.
When trying to write/read to/from the EEPROM, I never get the value that I suppose to be writing, the sketch always return "255"; tried to change the "base address" from 0x50 to 0x53 with the same results.
I have used this code before successfully in a Arduino Nano circuit, but using 24LC256 and a couple of AT24C1024B EEPROMS.
Any advice will be great.
Thanks in advance.
Using a nodeMCU, I'm trying to read and write an 24C08 I2C EEPROM, seems to be correctly wired, since the Nick Gammon's I2C Scanner detects the device and the neighbor DS1307 connected to the same bus.
The circuit have two 4K7 Ohm pull-up resistors connected to the 3V3 source available at some nodeMCU pins.
The scanner reports 5 devices (see attached image):
0x68, (the DS1307 RTC), and four devices (?) ranging from 0x50 to 0x53, the weird thing is the fact 24C08 EEPROM is supposed to answer only at the 0x50 address (all Address pins connected to GND, also the pin 7, Write Protect is connected to +5V).
I can control and use without problems the RTC; both DS1307 & the 24C08 are connected to the same +5V supply, so the wiring should be correctly cabled.
When trying to write/read to/from the EEPROM, I never get the value that I suppose to be writing, the sketch always return "255"; tried to change the "base address" from 0x50 to 0x53 with the same results.
I have used this code before successfully in a Arduino Nano circuit, but using 24LC256 and a couple of AT24C1024B EEPROMS.
Any advice will be great.
Thanks in advance.
Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////
// General include
#include <Wire.h>
#include <EEPROM.h>
/////////////////////////////////////////////////////////////////////////////////////////
// EEPROM definitions
unsigned int EEPROMBank = 0x50; // Base address of 1st EEPROM chip
unsigned int EEPROMAddress = 0; // Sets the start EEPROM address
unsigned int EEPROMValue = 0; // EEPROM value
byte Dummy;
// EEPROM list taken from:
// http://vascoferraz.com/projects/24c-eeprom-check/
// Sets the Maximum EEPROM address, uncomment accordingly:
//#define MaxBankAddress = 128 - 1; //24C01 -> 1024 bit -> 128 byte
//#define MaxBankAddress = 256 - 1; //24C02 -> 2048 bit -> 256 byte
//#define MaxBankAddress = 512 - 1; //24C04 -> 4096 bit -> 512 byte
unsigned int MaxBankAddress = 1024 - 1; //24C08 -> 8192 bit -> 1024 byte
//#define MaxBankAddress = 2048 - 1; //24C16 -> 16384 bit -> 2048 byte
//#define MaxBankAddress = 4096 - 1; //24C32 -> 32768 bit -> 4096 byte
//#define MaxBankAddress = 8192 - 1; //24C64 -> 65536 bit -> 8192 byte
//#define MaxBankAddress = 16384 - 1; //24C128 -> 131072 bit -> 16384 byte
//#define MaxBankAddress = 32768 - 1; //24C256 -> 262144 bit -> 32768 byte
//#define unsigned int maxaddress = 65536 - 1; //24C512 -> 524288 bit -> 65536 byte
/////////////////////////////////////////////////////////////////////////////////////////
// I2C definitions
#define SCLPin D1 // I2C SCL Pin
#define SDAPin D2 // I2C SDA Pin
/////////////////////////////////////////////////////////////////////////////////////////
// RTC DS1307 definitions
/////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// Wire.begin(); // Initialize 2-Wire bus
// http://www.esp8266.com/viewtopic.php?f=13&t=10374#p49060
// Wire.begin(int sda, int scl); // Initialize 2-Wire bus
Wire.begin(SDAPin, SCLPin); // Initialize 2-Wire bus
pinMode(D1, INPUT_PULLUP); // I Need to validate this line
pinMode(D2, INPUT_PULLUP); // I Need to validate this line
Serial.begin(19200); // Initialize serial port
while(!Serial); // wait for serial
delay(3000); // Waits 3 seconds
Serial.println("\n============================="); // Sends preamble and Cr+Lf
EEPROMAddress = 0; // EEPROM word variable
EEPROMValue = 123; // EEPROM value
Serial.print("EEPROMAddress: ");
Serial.print(EEPROMAddress);
Serial.print(", EEPROMValue: ");
Serial.print(EEPROMValue);
Serial.print(", EEPROMBank: 0x");
Serial.println(EEPROMBank,HEX);
writeEEPROM(EEPROMBank, EEPROMAddress, byte(EEPROMValue));
for (EEPROMAddress = 0; EEPROMAddress < 3; EEPROMAddress++) {
Serial.print("EEPROMAddress: ");
Serial.print(EEPROMAddress);
Serial.print(", Value: ");
Serial.println(readEEPROM(EEPROMBank, EEPROMAddress), DEC);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
void loop(){
// Do something useful here.
}
///////////////////////////////////////////////////////////////////////////////////////////
// http://www.hobbytronics.co.uk/arduino-external-eeprom
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
/////////////////////////////////////////////////////////////////////////////////////////
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
/////////////////////////////////////////////////////////////////////////////////////////