# voxl_i2c_read() function discards first byte from buffer

Source: https://forum.modalai.com/topic/2445/voxl_i2c_read-function-discards-first-byte-from-buffer
Category: Flight Core and Legacy VOXL (https://forum.modalai.com/category/9/flight-core-and-legacy-voxl)
Tags: i2c, voxl
Posted: 2023-07-19 15:41:11 UTC by jameskuesel
Replies: 3 · Views: 1779

## jameskuesel · 2023-07-19 15:41:11 UTC

Hello I am using the libaqp8096 i2c functions https://gitlab.com/voxl-public/voxl-sdk/core-libs/libapq8096-io/-/blob/master/lib/include/voxl_io.h specifically voxl_i2c_read() and voxl_i2c_write(). I am using the voxl read and write functions for reading and writing multiple bytes at a time. 

When I print out the read and write buffers, it looks like it properly writes to the buffer but the results from the read buffer are incomplete. For example, if I write uint8_t wrbuffer = 0x1234 to register address 0x0004, it writes 00 04 12 34 (the first two bytes for the address) and reads back 02 34. Another example: I wrote uint8_t wbuffer[4] = {33,55,77,99} and it read back 01 55 77 99. 

I noticed this issue happens with a write then read. If I read from a read-only buffer, it reads correctly.

## Reply by Eric Katzfey (ModalAI staff) · 2023-07-19 16:40:51 UTC

@jameskuesel What device do you have on the i2c bus?

## Reply by jameskuesel · 2023-07-19 18:46:55 UTC (in reply to Eric Katzfey)

@Eric-Katzfey a TOF ranging sensor - VL53L1CB by ST

## Reply by James Strawson (ModalAI staff) · 2023-07-20 17:38:45 UTC

hmmm, There is a similar (but not exactly the same) behavior with SPI on APQ8096 where all reads are preceded by a single random byte meaning libvoxl-io needs to read one extra byte than expected and then discard the first dummy byte. However this happens under the hood here:

https://gitlab.com/voxl-public/voxl-sdk/core-libs/libapq8096-io/-/blob/master/lib/sdsp/io_rpc_spi.c#L254

I've not seen such a thing with I2C. Have you looked at our VL53L1X driver for APQ8096? It might just work with your newer VL53L1CB sensors with small changes.

https://gitlab.com/voxl-public/voxl-sdk/services/apq8096-rangefinder-server
