24C256驱动代码 for Arduino
A0,A1,A2高电平,地址 0x50
连接方法:
如果使用Arduino UNO,Arduino pro mini,Arduino Micro
将芯片6脚连接Arduino A4(SDA),7脚连接Arduino A5(SCL)
示例读写程序:
int deviceaddress = 0x50 ;
void writeTest()
{
Wire.begin();
unsigned int address = 0;
writeEEPROM(address, 123);
Serial.print(readEEPROM(address), DEC);
}
void writeEEPROM(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(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;
}
参考:http://www.hobbytronics.co.uk/arduino-external-eeprom