Greetings!
I am controlling a capacitive touch panel using SSD2533 via I2C. The registers of SSD2533 are either 2 bytes or 4 bytes in length(i.e. 2 bytes or 4 bytes of data in 1 register address).
I have no trouble in writing the registers(two bytes to one register address). However, when I tried to read from a 4 bytes register, the Wire libraries seems to return and repeat only the 1st byte of the register.
I tried:
Wire.beginTransmission(TPadd);
Serial.print("Number of bytes sent:");
a = Wire.write(byte(0x7C));
Serial.println(a);
Wire.endTransmission();
b = Wire.requestFrom(TPadd, 4);
Serial.print("Number of bytes return:");
Serial.println(b);
Serial.println("Trying to read..");
while(4 <= Wire.available()) // slave may send less than requested
{
c1 = Wire.read(); // receive a byte as character
c2 = Wire.read();
c3 = Wire.read();
c4 = Wire.read();
Serial.println(c1,HEX); // print the character
Serial.println(c2,HEX);
Serial.println(c3,HEX);
Serial.println(c4,HEX);
}
Outputs :
Number of bytes sent:1
Number of bytes return:4
Trying to read..
D9
D9
D9
D9
where D9 is the reading of the x axis of touch panel. The rest bytes are eaten by the Wire lib.
I also tried:
Wire.beginTransmission(TPadd);
Serial.print("Number of bytes sent:");
a = Wire.write(byte(0x7C));
Serial.println(a);
Wire.endTransmission();
b = Wire.requestFrom(TPadd, 4);
Serial.print("Number of bytes return:");
Serial.println(b);
Serial.println("Trying to read..");
while(4 <= Wire.available()) // slave may send less than requested
{
c1 = Wire.read(); // receive a byte as character
c2 = Wire.read()<<8;
c3 = Wire.read()<<16;
c4 = Wire.read()<<24;
Serial.println(c1,HEX); // print the character
Serial.println(c2,HEX);
Serial.println(c3,HEX);
Serial.println(c4,HEX);
}
the outputs :
Number of bytes sent:1
Number of bytes return:4
Trying to read..
B6
0
0
0
where B6 is reading of x axis. The rest bytes are eaten by the Wire lib.
I am 100% sure that the I2C is returning the correct 1st byte data of the register. But how can I read the rest?
When I go to the wire lib, I found out that the buffer of I2C data register is 8bits. Anybody can help me out with this?
The following is the datasheet of the register:
The following is the recommended reading sequence: