EEPROM 24FC256-I/Pのスケッチ
(1)Wire Libraryを参照して、以下のスケッチを作成しました。
//EEPROM24FC256-I/P
#include <Wire.h>
#define disk1 0x50 //Address of 24LC256 eeprom chip
void setup(void)
{
Serial.begin(9600);
Wire.begin();
unsigned int address;
for(address=0;address<10;address++)
{
writeEEPROM(disk1, address, 255-address);
Serial.print(address, DEC);
Serial.print("\t");
Serial.println(readEEPROM(disk1, address), DEC);
}
}
void loop(){}
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;
}