ICM20689 - Motion Sensor#
Driver for the Invensense ICM20689 6-axis motion sensor.
Modules#
Functions#
Initialize the SPI bus to communicate with the ICM20689.
De-initialize the ICM20689 sensor.
Read register from the ICM20689 device.
Write a register in the ICM20689 device.
Perform soft reset on the ICM20689 chip.
Set the sample rate both of the accelerometer and the gyroscope.
Initialize the ICM20689 sensor.
Set the bandwidth of the gyroscope.
Set the bandwidth of the accelerometer.
Read the raw acceleration value and convert to g value based on the actual resolution.
Read the raw gyroscope value and convert to deg/sec value based on the actual resolution.
Get the actual resolution of the accelerometer.
Get the actual resolution of the gyroscope.
Set the full scale value of the accelerometer.
Set the full scale value of the gyroscope.
Enable or disable the sleep mode of the device.
Enable or disable the sensors in the ICM20689 chip.
Enable or disable the interrupts in the ICM20689 chip.
Read the interrupt status registers of the ICM20689 chip.
Check if new data is available to read.
Accelerometer and gyroscope calibration function.
Gyroscope calibration function.
Read the temperature sensor raw value and convert to Celsius.
Read the device ID of the ICM20689.
Function Documentation#
sl_icm20689_spi_init#
sl_status_t sl_icm20689_spi_init (void )
Initialize the SPI bus to communicate with the ICM20689.
N/A |
Returns
Returns zero on OK, non-zero otherwise
118
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_deinit#
sl_status_t sl_icm20689_deinit (void )
De-initialize the ICM20689 sensor.
N/A |
Returns
Returns zero on OK, non-zero otherwise
127
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_read_register#
sl_status_t sl_icm20689_read_register (uint8_t addr, int num_bytes, uint8_t * data)
Read register from the ICM20689 device.
[in] | addr | The register address to read from in the sensor Bit[7:0] - register address |
[in] | num_bytes | The number of bytes to read |
[out] | data | The data read from the register |
Returns
Returns zero on OK, non-zero otherwise
146
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_write_register#
sl_status_t sl_icm20689_write_register (uint8_t addr, uint8_t data)
Write a register in the ICM20689 device.
[in] | addr | The register address to write Bit[7:0] - register address |
[in] | data | The data to write to the register |
Returns
Returns zero on OK, non-zero otherwise
162
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_reset#
sl_status_t sl_icm20689_reset (void )
Perform soft reset on the ICM20689 chip.
N/A |
Returns
Returns zero on OK, non-zero otherwise
171
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_set_sample_rate#
float sl_icm20689_set_sample_rate (float sample_rate)
Set the sample rate both of the accelerometer and the gyroscope.
[in] | sample_rate | The desired sample rate in Hz. |
Returns
The actual sample rate, which may be different than the desired value because of the finite and discrete number of divider settings.
184
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_init#
sl_status_t sl_icm20689_init (void )
Initialize the ICM20689 sensor.
N/A |
Enable the power supply and SPI lines, set up the host SPI controller, configure the chip control interface, clock generator, and interrupt line.
Returns
Returns zero on OK, non-zero otherwise
195
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_gyro_set_bandwidth#
sl_status_t sl_icm20689_gyro_set_bandwidth (sl_gyro_bandwidth_t gyro_bandwidth)
Set the bandwidth of the gyroscope.
[in] | gyro_bandwidth | The desired bandwidth value. Use the sl_gyro_bandwidth_t enum, which are defined in the icm20689.h file. The value of x can be 5Hz, 10Hz, 20Hz, 41Hz, 92Hz, 176Hz, 250Hz, 3281Hz or 8173Hz with or without digital low pass filter(DLPF). |
Returns
Returns zero on OK, non-zero otherwise
210
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_accel_set_bandwidth#
sl_status_t sl_icm20689_accel_set_bandwidth (sl_accel_bandwidth_t accel_bandwidth)
Set the bandwidth of the accelerometer.
[in] | accel_bandwidth | The desired bandwidth value. Use the sl_accel_bandwidth_t enum, which are defined in the icm20689.h file. The value of y can be 5.1Hz, 10.2Hz, 21.2Hz, 44.8Hz, 99Hz, 218.1Hz(0), 218.1Hz(1), 420Hz or 1046Hz. 1046Hz is the only value without digital low pass filter. |
Returns
Returns zero on OK, non-zero otherwise
225
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_accel_read_data#
sl_status_t sl_icm20689_accel_read_data (float accel)
Read the raw acceleration value and convert to g value based on the actual resolution.
[out] | accel | A 3-element array of float numbers containing the acceleration values for the x, y and z axes in g units. |
Returns
Returns zero on OK, non-zero otherwise
239
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_gyro_read_data#
sl_status_t sl_icm20689_gyro_read_data (float gyro)
Read the raw gyroscope value and convert to deg/sec value based on the actual resolution.
[out] | gyro | A 3-element array of float numbers containing the gyroscope values for the x, y and z axes in deg/sec units. |
Returns
Returns zero on OK, non-zero otherwise
253
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_accel_get_resolution#
sl_status_t sl_icm20689_accel_get_resolution (float * accel_res)
Get the actual resolution of the accelerometer.
[out] | accel_res | The resolution in g/bit units |
Returns
Returns zero on OK, non-zero otherwise
265
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_gyro_get_resolution#
sl_status_t sl_icm20689_gyro_get_resolution (float * gyro_res)
Get the actual resolution of the gyroscope.
[out] | gyro_res | The actual resolution in (deg/sec)/bit units |
Returns
Returns zero on OK, non-zero otherwise
277
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_accel_set_full_scale#
sl_status_t sl_icm20689_accel_set_full_scale (sl_accel_full_scale_t accel_fs)
Set the full scale value of the accelerometer.
[in] | accel_fs | The desired full scale value. The value of x can be 2, 4, 8 or 16. |
Returns
Returns zero on OK, non-zero otherwise
290
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_gyro_set_full_scale#
sl_status_t sl_icm20689_gyro_set_full_scale (sl_gyro_full_scale_t gyro_fs)
Set the full scale value of the gyroscope.
[in] | gyro_fs | The desired full scale value. The value of y can be 250, 500, 1000 or 2000. |
Returns
Returns zero on OK, non-zero otherwise
303
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_enable_sleep_mode#
sl_status_t sl_icm20689_enable_sleep_mode (bool enable)
Enable or disable the sleep mode of the device.
[in] | enable | If true, sleep mode is enabled. Set to false to disable sleep mode. |
Returns
Returns zero on OK, non-zero otherwise
315
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_enable_sensor#
sl_status_t sl_icm20689_enable_sensor (bool accel, bool gyro, bool temp)
Enable or disable the sensors in the ICM20689 chip.
[in] | accel | If true, enables the acceleration sensor |
[in] | gyro | If true, enables the gyroscope sensor |
[in] | temp | If true, enables the temperature sensor |
Returns
Returns zero on OK, non-zero otherwise
333
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_enable_interrupt#
sl_status_t sl_icm20689_enable_interrupt (bool data_ready_enable, bool wom_enable)
Enable or disable the interrupts in the ICM20689 chip.
[in] | data_ready_enable | If true, enables the Raw Data Ready interrupt, otherwise disables. |
[in] | wom_enable | If true, enables the Wake-up On Motion interrupt, otherwise disables. |
Returns
Returns zero on OK, non-zero otherwise
348
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_read_interrupt_status#
sl_status_t sl_icm20689_read_interrupt_status (uint32_t * int_status)
Read the interrupt status registers of the ICM20689 chip.
[out] | int_status | The content the four interrupt registers. LSByte is INT_STATUS, MSByte is INT_STATUS_3 |
Returns
Returns zero on OK, non-zero otherwise
361
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_is_data_ready#
bool sl_icm20689_is_data_ready (void )
Check if new data is available to read.
N/A |
Returns
Returns true if the Raw Data Ready interrupt bit set, false otherwise
370
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_calibrate_accel_and_gyro#
sl_status_t sl_icm20689_calibrate_accel_and_gyro (float * accel_bias_scaled, float * gyro_bias_scaled)
Accelerometer and gyroscope calibration function.
[out] | accel_bias_scaled | The mesured acceleration sensor bias in mg |
[out] | gyro_bias_scaled | The mesured gyro sensor bias in deg/sec |
Reads the gyroscope and accelerometer values while the device is at rest and in level. The resulting values are loaded to the accel and gyro bias registers to cancel the static offset error.
Returns
Returns zero on OK, non-zero otherwise
388
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_calibrate_gyro#
sl_status_t sl_icm20689_calibrate_gyro (float * gyro_bias_scaled)
Gyroscope calibration function.
[out] | gyro_bias_scaled | The mesured gyro sensor bias in deg/sec |
Read the gyroscope values while the device is at rest and in level. The resulting values are loaded to the gyro bias registers to cancel the static offset error.
Returns
Returns zero on OK, non-zero otherwise
403
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_read_temperature_data#
sl_status_t sl_icm20689_read_temperature_data (float * temperature)
Read the temperature sensor raw value and convert to Celsius.
[out] | temperature | The mesured temperature in Celsius |
Returns
Returns zero on OK, non-zero otherwise
415
of file hardware/driver/icm20689/inc/sl_icm20689.h
sl_icm20689_get_device_id#
sl_status_t sl_icm20689_get_device_id (uint8_t * dev_id)
Read the device ID of the ICM20689.
[out] | dev_id | The ID of the device read from the WHO_AM_I register. Expected value 0x98. |
Returns
Returns zero on OK, non-zero otherwise
427
of file hardware/driver/icm20689/inc/sl_icm20689.h