Du hast ja recht - ich würde gerne weniger dranhängen.
Die BID-Stecker am Ladegerät haben 4 Pins: Vcc, SDA, SCL und GND - was das EEPROM auf den BID-Platinchen halt so braucht. Perverserweise ist Vcc bei beiden Ladegeräten nahe an 5V und die (mit Oszi nachgemessenen) Pegel auf SDA und SL haben nur 3.3V.
Masse zu verbinden habe ich bei dem Versuch mit dem LevelShifter gemacht - ohne Erfolg. Ergibt das bei der optischen Trennung wirklich Sinn?
Und hier ist der Sketch (der aber mit einem Arduino als Master und einem als Slave das tut was ich erwarte).
#include <Wire.h>
#include <EEPROM.h>
#include <string.h>
const uint8_t BID_CHIP_ADDRESS = 0x50;
int requestCount = 0;
int receiveCount = 0;
int oldRequestCount = 0;
int oldReceiveCount = 0;
byte muell;
byte bidAddress = 0;
byte bidData[256] =
{
0x01, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x02, 0x01, 0x00, 0x64, 0x00,
0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x02, 0x01, 0x00, 0x64, 0x00,
0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup()
{
Serial.begin(9600); // begin serial communication
while(!Serial)
{
;
}
Serial.println(F("EEPROM CLIENT"));
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
Wire.begin(BID_CHIP_ADDRESS);
}
void loop()
{
if (Serial.available())
{
byte cmd = Serial.read();
while(Serial.available())
{
muell = Serial.read();
}
switch (cmd)
{
case 'w':
Serial.println("put data");
EEPROM.put(0, bidData);
break;
case 'r':
Serial.println("get data");
EEPROM.get(0, bidData);
break;
case 'i':
Serial.print("RQ ");
Serial.print(requestCount);
Serial.print(" - RV ");
Serial.println(receiveCount);
break;
default:
break;
}
}
}
void receiveEvent(int numberOfBytes)
{
byte address;
byte value;
bool writeAccess = false;
while (1 < Wire.available())
{
address = Wire.read();
writeAccess = true;
receiveCount++;
}
value = Wire.read();
receiveCount++;
if (writeAccess)
{
bidData[address] = value;
bidAddress = address;
}
else
{
bidAddress = value;
}
}
void requestEvent()
{
Wire.write(bidData[bidAddress]);
bidAddress++;
requestCount++;
}