sizeof(somedataA) hat den Wert 13, weil auch die abschließende '\0' mitgezählt wird.
Es geht auch ohne page, nur eben langsamer:
#include <Wire.h>
void i2c_eeprom_writeByte(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(10);
}
byte i2c_eeprom_read_byte( 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;
};
void MemoryDump(int deviceaddress, unsigned int NumberOfBytes)
{
Serial.print(F("Dump of memory content ("));
Serial.print(NumberOfBytes);
Serial.print(F(" bytes) from I2C device at address "));
Serial.println(deviceaddress, HEX);
unsigned int addr = 0;
byte b = i2c_eeprom_read_byte(deviceaddress, addr);
char c;
while (addr < NumberOfBytes)
{
Serial.print(addr, HEX);
Serial.print(" ");
c = (char)b;
Serial.print(c); //print content to serial port
// if ( (b < 0x20) or (b >= 0x7F) )
// {
Serial.print(" (0x");
Serial.print(b, HEX);
Serial.print(")");
// };
Serial.println();
addr++; //increase address
b = i2c_eeprom_read_byte(deviceaddress, addr);
};
Serial.println(F("\nEnd of Dump\n"));
};
void setup()
{
char somedataA[] = "ICEFILAMENTS";
char somedataB[] = "icefilaments";
const byte I2C_EEPROM_ADDRESS = 0x57;
Wire.begin();
Serial.begin(9600);
Serial.println(F("\nAnfang EEPROM 24c32\n"));
Serial.print(I2C_EEPROM_ADDRESS);
Serial.print(" (0x");
Serial.print(I2C_EEPROM_ADDRESS, HEX);
Serial.println(")");
i2c_eeprom_write (I2C_EEPROM_ADDRESS, 100, (byte *)somedataA, sizeof(somedataA)-1 );
delay(20);
i2c_eeprom_write (I2C_EEPROM_ADDRESS, 112, (byte *)somedataB, sizeof(somedataB)-1 );
delay(20);
MemoryDump(I2C_EEPROM_ADDRESS, 124);
};
void loop() {};
void i2c_eeprom_write( int i2cadresse, unsigned int eeaddress, byte* data, byte length ) {
for ( byte c = 0; c < length; c++) {
i2c_eeprom_writeByte(i2cadresse, eeaddress + c, data[c]);
}
}
Ist zusammenkopiert, könntest Du für Deine Zwecke optimieren.
Ausgabe:
60 ⸮ (0xFF)
61 ⸮ (0xFF)
62 ⸮ (0xFF)
63 ⸮ (0xFF)
64 I (0x49)
65 C (0x43)
66 E (0x45)
67 F (0x46)
68 I (0x49)
69 L (0x4C)
6A A (0x41)
6B M (0x4D)
6C E (0x45)
6D N (0x4E)
6E T (0x54)
6F S (0x53)
70 i (0x69)
71 c (0x63)
72 e (0x65)
73 f (0x66)
74 i (0x69)
75 l (0x6C)
76 a (0x61)
77 m (0x6D)
78 e (0x65)
79 n (0x6E)
7A t (0x74)
7B s (0x73)
End of Dump
Das von @combie ist vermutlich besser ![]()