Hi all,
after reading everything i could read in the nternet i struggle.... please help:
I want to write & re-read a value into a eeprom from an ardunio nano.
Hardware-setup:
Arduino: Nano
Eeprom: CAT24C512 (DatasheetCAT24C512YI-GT3, )
Wire: Arduino_SDA->Eeprom_SDA
Wire: Arduino_SDA->10kOhm->Vcc (5v)
Wire: Arduino_SCL->Eeprom_SCL
Wire: Arduino_SCL->10kOhm->Vcc (5v)
Wire: Eeprom_A0 -> VCC
Wire: Eeprom_A1 -> VCC
Wire: Eeprom_A2 -> GND
Wire: Eeprom_W -> floating (according to datasheet there is a integrated pull-down)
Wire: Eeprom_VCC -> VCC
Wire: Eeprom_GND -> GND
All wires are less then 5 cm.
Used code:
#include <Wire.h>
#define DEVICEADDRESS_READ ((uint8_t)(0b01010000))
uint8_t deviceadress= 0;void mywrite(uint8_t my_device_address, uint16_t theMemoryAddress, uint8_t u8Byte)
{
Wire.beginTransmission(my_device_address);
Wire.write((uint8_t) (((theMemoryAddress >> 8 ) ) & 0xFF) );
Wire.write((uint8_t) (((theMemoryAddress ) ) & 0xFF) );
Wire.write((uint8_t) u8Byte);
Wire.endTransmission();
delay(10);
}uint8_t myread(uint8_t my_device_address,uint16_t theMemoryAddress)
{
uint8_t u8retVal = 0;
Wire.beginTransmission(my_device_address);
Wire.write((uint8_t) (((theMemoryAddress >> 8 ) ) & 0xFF) );
Wire.write((uint8_t) (((theMemoryAddress ) ) & 0xFF) );
Wire.endTransmission();
delay(5);
Wire.requestFrom(my_device_address, (uint8_t)1);
if (Wire.available()) u8retVal = Wire.read();
return u8retVal ;
}void setup() {
Serial.begin(9600); while (!Serial) { ; }
Wire.begin();
// Wire.setClock(100000L);
}void loop() {
Serial.println("start");
deviceadress=DEVICEADDRESS_READ;
uint8_t write_value = 42;// try all 8 possible device addresses....
for (uint8_t i=deviceadress;i<(deviceadress+8);i++) {
Serial.print("device-id=");
Serial.print(i);
Serial.print(" write=");
Serial.print(write_value);
mywrite(i,0,write_value);
Serial.print(" re-read=");
uint8_t value = myread(i,0);
Serial.println(value);
}
Serial.println("end");for ( ; ; ) { } // end of live
}
Produced output from the code in serial monitor
start
device-id=80 write=42 re-read=0
device-id=81 write=42 re-read=0
device-id=82 write=42 re-read=0
device-id=83 write=42 re-read=0
device-id=84 write=42 re-read=0
device-id=85 write=42 re-read=0
device-id=86 write=42 re-read=0
device-id=87 write=42 re-read=0
end
Remark: The device address should be "1010 A2 A1 A0". In my test programm i used all 8 addresses .... the chip should respond at address "1010011" .... but nothing happens.
If i change the initial 'default value' ( uint8_t u8retVal = 0; ) to e.g. 66 - this value will be returned.
If i just read the value from I2C without ( if (Wire.available()) ) then the return value is 255.
Remark:
The SDA & SCL Pins does have +5v (multimeter measurement).
The VCC and GND pins does have VCC/GND level. All wires does not have shorts to other potentials. Unfortunately i do not own a logic analyser - so i cannot look at the I2C lines.
Any Ideas ?