I have been trying to read FIFO buffer from LSM6DS3 inertial sensor via i2c. The processor will read LSM6DS3 buffer every 20s so the FIFO will contain approximately 3120 bytes of accelerometer data. The sensor contains 2 registers to read FIFO data which are FIFO_DATA_OUT_L and FIFO_DATA_OUT_H.
In my host, I use read-write system call to communicate with the sensor. And My i2c clock is 400KHz also I have couple of other devices connected on the same bus.
i2c_init()
{
fd_i2c4=open("/dev/i2c-4",O_RDWR);/*open i2c. fd_i2c4 is global*/
if(fd_i2c4<0)
{
perror("i2c device open : ");
BLOGV(LOG_TAG "i2c device open error");
return -1;
}
if(ioctl(fd_i2c4,I2C_SLAVE,addr)<0)
{
perror("i2c slave error : ");
BLOGV(LOG_TAG "i2c slave error");
return -1;
}
}
This is my i2c read function
static int32_t i2c_read_low_latency(int *file,__u8 reg,__u8 *buff,__u16 len)
{
buff[0]=reg;
int temp=write(*file, buff, 1);
temp=read(*file, buff, len);
if ( temp!= len) {
/* ERROR HANDLING: i2c transaction failed */
printf("i2c read error \n");
}
return 0;
}
and FIFO reading function pseudo code,
fifo_read()
{
int fifo length=get_fifo_data_level() //to get number of available data in fifo.
while(length-- >0)
{
i2c_read_low_latency(&fd_i2c4,LSM6DS3_FIFO_DATA_OUT_L,ch,2); // x axis data.
i2c_read_low_latency(&fd_i2c4,LSM6DS3_FIFO_DATA_OUT_L,ch,2); // y axis data.
i2c_read_low_latency(&fd_i2c4,LSM6DS3_FIFO_DATA_OUT_L,ch,2); // z axis data.
}
}
The problem is it takes around 2-3 sec to read complete data. this consumes lot of power. Any idea why this slow reading?. link to data sheet lsm6ds3