I am trying to interface a MLX90640 Thermal Image camera to a Raspberry Pi5 over I2C using C. The register addresses are 2byte words, so SMBus/ioctl seems unworkable (as it uses 1 byte register addresses only).
I have tried using the standard Unix read() and write() functions and the Logic analyzer trace shows everything working more or less as expected.
The problem I have seems to be that when trying to read a register the initial write sends the correct data BUT adds a STOP bit, which seems to prevent the subsequent read() from reading the correct register. The result is that a read ALWAYS returns the same values.
Is there any way I can prevent a write() before a read() from sending the stop bit?
The open command is: if(0 > (fh = open("/dev/i2c-1", O_RDWR))) {
The initial write: if(2 != (res = write(fh, msg, 2))) {
The subsequent read: if(4 != (res = read(fh, resp, 4))) {
The msg and resp are uint8_t arrays.
Or is there another library I should be using that works on RPi5?