I am trying to use ICM42605 sensor for my project. I set accelerometer and gyroscope sensitivity to 16G and 2000dps accordingly. When I read the data I notices that accelerometer data that i get is 2000 at rest on any axis. If I change sensitivity to 8G the reading becomes 4000, and at 4G it is 8000. What am i missing to convert the reading to G units?? Here is the code of set up and read data function:
void icm42605_init_hardware(icm42605_t * imu)
{
send_command(PWR_MGMT0, TEMP_DIS | ACCEL_MODE_LN | GYRO_MODE_LN | 0x01 << 4, imu);
nrf_delay_ms(100);
send_command(GYRO_CONFIG0, GYRO_FS_SEL_2000 | GYRO_ODR_500, imu);
nrf_delay_ms(50);
send_command(ACCEL_CONFIG0, ACCEL_FS_SEL_16G | ACCEL_ODR_500, imu);
nrf_delay_ms(50);
send_command(0x53, 0x01 << 3 | 0x2 << 1, imu);
}
void icm42605_get_sensor_data(icm42605_t * imu, uint16_t * accel, uint16_t * gyro)
{
spi_read_X_bytes(imu, ACCEL_DATA_X1, 12);
accel[0] = (imu->spi_rx_buf[1] << 8) | imu->spi_rx_buf[2];
accel[1] = (imu->spi_rx_buf[3] << 8) | imu->spi_rx_buf[4];
accel[2] = (imu->spi_rx_buf[5] << 8) | imu->spi_rx_buf[6];
gyro[0] = (imu->spi_rx_buf[7] << 8) | imu->spi_rx_buf[8];
gyro[1] = (imu->spi_rx_buf[9] << 8) | imu->spi_rx_buf[10];
gyro[2] = (imu->spi_rx_buf[11] << 8) | imu->spi_rx_buf[12];
}
And here is a call to the read and display:
int16_t gyro[3];
int16_t accel[3];
icm42605_get_sensor_data(&m_imu, accel, gyro);
printf("Accel X: %d, Y: %d, Z: %d Gyro X: %d, Y: %d, Z: %d\r\n",
accel[0], accel[1], accel[2],
gyro[0], gyro[1], gyro[2]);
This is what I get:
Accel X: 123, Y: -2045, Z: -45 Gyro X: 95, Y: -289, Z: -683
Thank you.