ecco il codice
#include <Wire.h>
#define EERPOM_1_ADDRESS 80
#define EERPOM_2_ADDRESS 87
void connectPage(int address, int page){
Wire.beginTransmission(address);
Wire.send((int)((page) >> 8));
Wire.send((int)((page) & 0xFF));
}
void request(int address, int nData){
Wire.endTransmission();
Wire.requestFrom(address, nData);
}
void sendRandomData(){
int j = 0;
Wire.endTransmission();
for(int i = 0; i < 10; i++){
Wire.send((byte) (j = (byte) random()));
Serial.println(j);
}
Serial.println("fine invio dati");
}
void setup(){
Serial.begin(9600);
Wire.begin(EERPOM_1_ADDRESS);
connectPage(EERPOM_1_ADDRESS, 150);
sendRandomData();
connectPage(EERPOM_1_ADDRESS, 150);
request(EERPOM_1_ADDRESS, 10);
while(Wire.available())
Serial.println((int) Wire.receive());
Serial.println("Turno 2");
Wire.begin(EERPOM_2_ADDRESS);
connectPage(EERPOM_2_ADDRESS, 200);
sendRandomData();
connectPage(EERPOM_2_ADDRESS, 200);
request(EERPOM_2_ADDRESS, 10);
while(Wire.available())
Serial.println((int) Wire.receive());
}
void loop(){
}
ed ecco i risultati
167
241
217
42
130
200
216
254
67
77
fine invio dati
255
255
255
255
255
255
255
255
255
255
Turno 2
152
85
140
226
179
71
23
17
152
84
fine invio dati
255
255
255
255
255
255
255
255
255
255
come si vede non "recupero" quello che salvo...
però non succede che si blocca la Wire.endTransmission(), cosa che succedeva tempo fa...
