PLS 62-W EEPROM (AT24C08) with Interface I2cBusConnection | Telit Cinterion IoT Developer Community
April 9, 2019 - 3:21am, 2773 views
I'm having a hard time using the I2c Bus Connection interface to write and read data to the EEPROM AT24C08. As shown in the java document, for you to perform a write operation, you must send the command below to perform data writing.
Byte write EEPROM structure :
[Start|A0|addrress high|adress low|data in|Stop]
My messagem = <AA0000006>
"<" ->Start Transfer Message
"A" -> 8 bit ID
"A0" -> EEPROM slave ID = 1010-0000 -> data write mode according to datasheet
"00" -> Most significan bit = adress high
"00" -> least significant bit = address low
"06" -> Data in
">" -> Stop
I get the (+) transmission OK, but the data is not recorded and I can not read a byte
Read EEPROM structure :
[Start |A0|address high|address low|restart|A1|Dataout|Stop]
Hello,
Could you paste the complete log to also show how you read the data and what the reply is?
Regards,
Bartłomiej
Hello Bartłomiej
Initially I used the Java documentation example:
Write Transfer Frame, where a = message ID, AE = Slave Address and write request:
Read response message: {a+} where a = message ID:
String response = byteArrayToHexString(inBuf);
checkResponseAck(response);
System.out.printl(response);
If the memory is connected to the module the answer is {+} its disconnected to the power the answer is {-} but I'm a little confused the documentation is not very explanatory
Aux methods
private boolean checkResponseAck(String responseIn) {
final boolean DEBUG = false;
boolean retVal = false;
if (DEBUG) {System.out.println("[I2CHandler]: I2C response = " + responseIn);}
if (responseIn != null) {
retVal = true;
// Response Message: (AT Command guide - Table 19.3)
// {ID + } Write OK
// {ID + Data } Read of x bytes OK
// {ID - **** } NAK for xth byte if Read or Write
// {ID ! **** } Protocol error in xth byte
if (responseIn.indexOf("{a+") == -1) {
retVal = false;
if (responseIn.indexOf("{a-") > -1) {
if (DEBUG) {System.out.println("[I2CHandler]: I2C command not acknowledged: '" + responseIn + "'");}
}
if (responseIn.indexOf("{a!") > -1) {
System.out.println("[I2CHandler]: I2C command protocol error: '" + responseIn + "'");
}
}
} else {
System.out.println("[I2CHandler]: Warning checkResponseAck() called but responseIn == null");
}
return retVal;
}
// This will give two-char length string for an int.
public String intToHex(int i){
final char[] Hex = "0123456789ABCDEF".toCharArray();
return "" + Hex[(i & 0xF0) >> 4] + Hex[(i & 0x0F)];
}
// This will give multiple two-char pairs string for a byte array.
public String byteArrayToHexString(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int v;
for ( int j = 0; j < bytes.length; j++ ) {
v = bytes[j] & 0xFF;
hexChars[j*2] = HEX_ARRAY[v/16]; // method 1
hexChars[j*2 + 1] = HEX_ARRAY[v%16]; // method 1
}
return new String(hexChars);
}
public static String byteArrayToHexString(byte[] bytesIn) {
final char[] HEX_ARRAY = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char[] hexChars;
int j;
int v;
if (bytesIn != null) {
hexChars = new char[bytesIn.length * 2];
for (j = 0; j < bytesIn.length; j++) {
v = bytesIn[j] & 0xFF;
hexChars[j * 2] = HEX_ARRAY[v / 16];
hexChars[j * 2 + 1] = HEX_ARRAY[v % 16];
}
return new String(hexChars);
} else {
System.out.println("[Modbus]: byteArrayToHexString() null pointer.");
return null;
}
}
Hello,
The reply suggests that the data was accepted by the device. Could you paste the log that shows reading - what exactly is sent and what the reply is?
Regards,
Bartłomiej
The write response of the byte always {id +}
I'm just confused at the time of performing the reading operation and a little bit about using the API. I have attached the eeprom memory document
I need create methods to salve and read short (2bytes) variables in eeprom 8k (1024x8)
Log response:
I2C test
[I2C]: + openI2Cbus
[I2C]: I2Cbus opened !!!
[I2C]: - openI2Cbus
[I2C]: Comand write: <AA0000902>
[I2C]: + openI2Cbus
[I2C]: - openI2Cbus
[I2C]: I2C chanel == true
[I2C]: Delay write == 0
[I2C]: Delay == 0 e Outputstream
[I2C]: Data salved
[I2C]: sendCommand() flush()
[I2C]: response == [{A+}]
[I2C]: Comando write: <AA00000<A10000>>
[I2C]: + openI2Cbus
[I2C]: - openI2Cbus
[I2C]: Canal I2C chanel == true
[I2C]: Delay write == 0
[I2C]: Delay == 0 e Outputstream
I think that it would be easier to use AT commands for testing. Just try to write and read with AT commands as shown in AT commands specification and paste the output from reading and writing.