04-10-2015, 15:30
Mam pytanie czy ma ktos prosty program do zapisu i odczytu tej pamięci
Ocena wątku:
24c02 eeprom i2c
|
#include <Wire.h>
#define device 0x50
void setup() {
Wire.begin();
Serial.begin(9600);
delay(500);
byte data, wordaddress;
data = 0x01;
wordaddress = 0x01;
byte index;
for(index=0x01;index<=5;index++){
showWrite(data,wordaddress);
deviceWrite(data,wordaddress);
wordaddress++;
data++;
delay(1500);
};
delay(3000);
wordaddress = 0x01;
for(index=0x01;index<=5;index++){
data = deviceRead(wordaddress);
showRead(data,wordaddress);
delay(1500);
wordaddress++;
};
delay(3000);
}
void showRead(byte data, byte wordaddress){
Serial.print("Read data: ");
Serial.print(data,HEX);
Serial.print(" from: ");
Serial.println(wordaddress,HEX);
}
void showWrite(byte data, byte wordaddress){
Serial.print("Write data: ");
Serial.print(data,HEX);
Serial.print(" to: ");
Serial.println(wordaddress,HEX);
}
void deviceWrite(byte data, byte wordaddress) {
Wire.beginTransmission(device);
Wire.write(wordaddress);
Wire.write(data);
Wire.endTransmission();
}
byte deviceRead(byte wordaddress) {
byte result;
int i;
Wire.beginTransmission(device);
Wire.write(wordaddress);
Wire.endTransmission();
Wire.requestFrom(device, 1);
if(Wire.available()) {
result = Wire.read();
}
Wire.endTransmission();
return result;
}
void loop() {
}