How to read I2C device registry with the new i2c_api.h API? E.g. EEPROM or value from accelerometer.
It seems this API is missing function like HAL_I2C_Mem_Read() available in stm32f7xx_hal_i2c.h.
Or is it me missing something?
Below is what I have tried. The code fails while reading (value = -1).
#include "i2c_api.h"
#include "mbed_error.h"
i2c_t i2c;
i2c_init(&i2c, PB_7_ALT0, PD_12);
for (uint32_t offset = 0; offset < 256; offset++) {
i2c_start(&i2c);
//written = i2c_write(&i2c, Address, (char[]){offset}, 1, 0); // nack
int written1 = i2c_byte_write(&i2c, Address);
int written2 = i2c_byte_write(&i2c, offset);
i2c_start(&i2c);
int written3 = i2c_byte_write(&i2c, Address + 1);
int value = i2c_byte_read(&i2c, 1); // nack
if (written1 != 1 || written2 != 1 || written2 != 1 || value < 0) {
mbed_error_printf("Error writting to device. Write1: %d, Write2: %d, Write3: %d, Value: %d", written1, written2, written3, value);
break;
} else {
mbed_error_printf("Device read: 0x%X = 0x%X\r\n", offset, value);
}
}