I have an i2c device that i would like to rreverse engineer. Using the oringal master of the device here is a snapshot from the logical analyzer
I would like to replace the orginal master of the device with an arduino, the device has an interrupt pin that when detected it will do the trasaction above.
So far what i have figuerd out is the address is 0x53 (the first byte). I have also figured out by interactive with the device that the second,third, and last byte are data from the slave device.
How do i write an arduino code to simulate this transaction? Here is the code i have written and the response i got is not quite the same
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Wire. setClock(100000)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(0x53, 6); // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
1 Answer 1
Customised Protocol
As has been mentioned in the comments, it may be that the controller and target are communicating using a customised protocol for which you will need to modify the Wire
library and/or the TWI
library.
Modifying the TWI
library is not easy because it uses a very convoluted mixture of ISR code and non-ISR polling code.
I've re-written the TWI library so that you can use standard burst-read and burst-write protocols in either ISR mode or polling mode, or build your own protocol using building-block functions. It uses the watchdog timer to detect timeouts when the bus freezes due to an error.
Terminology
The terminology of my TWI library conforms to NXP Semiconductors recently released v7 of the I2C-bus specification which has:
Updated the terms "master/slave" to "controller/target" throughout to align with MIPI I3C specification and NXP's Inclusive Language Project
UM10204, I2C-bus specification and user manual, v7, 2021年10月01日, Table 1, Revision history
Wire
library. Though I doubt that this would help. The delay is introduced by the master (since if the slave would do the clock stretching here the Arduino couldn't overcome this). Why would the slave need it? It perfectly works in the communication. In I2C when the slave is too slow for the master the communication normally totally breaks apart, mostly resulting in a blocked I2C bus. Also you can see in the first picture, that the slave is releasing SDA line right after the acknowledgement pulse. That suggest, that it isn't too slow.