ICM20689 - Motion Sensor#

Driver for the Invensense ICM20689 6-axis motion sensor.

Modules#

Register definitions

Functions#

sl_status_t

Initialize the SPI bus to communicate with the ICM20689.

sl_status_t

De-initialize the ICM20689 sensor.

sl_status_t
sl_icm20689_read_register(uint8_t addr, int num_bytes, uint8_t *data)

Read register from the ICM20689 device.

sl_status_t
sl_icm20689_write_register(uint8_t addr, uint8_t data)

Write a register in the ICM20689 device.

sl_status_t

Perform soft reset on the ICM20689 chip.

float
sl_icm20689_set_sample_rate(float sample_rate)

Set the sample rate both of the accelerometer and the gyroscope.

sl_status_t

Initialize the ICM20689 sensor.

sl_status_t
sl_icm20689_gyro_set_bandwidth(sl_gyro_bandwidth_t gyro_bandwidth)

Set the bandwidth of the gyroscope.

sl_status_t
sl_icm20689_accel_set_bandwidth(sl_accel_bandwidth_t accel_bandwidth)

Set the bandwidth of the accelerometer.

sl_status_t

Read the raw acceleration value and convert to g value based on the actual resolution.

sl_status_t

Read the raw gyroscope value and convert to deg/sec value based on the actual resolution.

sl_status_t

Get the actual resolution of the accelerometer.

sl_status_t

Get the actual resolution of the gyroscope.

sl_status_t
sl_icm20689_accel_set_full_scale(sl_accel_full_scale_t accel_fs)

Set the full scale value of the accelerometer.

sl_status_t
sl_icm20689_gyro_set_full_scale(sl_gyro_full_scale_t gyro_fs)

Set the full scale value of the gyroscope.

sl_status_t

Enable or disable the sleep mode of the device.

sl_status_t
sl_icm20689_enable_sensor(bool accel, bool gyro, bool temp)

Enable or disable the sensors in the ICM20689 chip.

sl_status_t
sl_icm20689_enable_interrupt(bool data_ready_enable, bool wom_enable)

Enable or disable the interrupts in the ICM20689 chip.

sl_status_t
sl_icm20689_read_interrupt_status(uint32_t *int_status)

Read the interrupt status registers of the ICM20689 chip.

bool

Check if new data is available to read.

sl_status_t
sl_icm20689_calibrate_accel_and_gyro(float *accel_bias_scaled, float *gyro_bias_scaled)

Accelerometer and gyroscope calibration function.

sl_status_t
sl_icm20689_calibrate_gyro(float *gyro_bias_scaled)

Gyroscope calibration function.

sl_status_t

Read the temperature sensor raw value and convert to Celsius.

sl_status_t
sl_icm20689_get_device_id(uint8_t *dev_id)

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.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[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.


Definition at line 184 of file hardware/driver/icm20689/inc/sl_icm20689.h

sl_icm20689_init#

sl_status_t sl_icm20689_init (void )

Initialize the ICM20689 sensor.

Parameters
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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[out]accel_res

The resolution in g/bit units

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[out]gyro_res

The actual resolution in (deg/sec)/bit units

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[in]enable

If true, sleep mode is enabled. Set to false to disable sleep mode.

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
N/A

Returns

  • Returns true if the Raw Data Ready interrupt bit set, false otherwise


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[out]temperature

The mesured temperature in Celsius

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[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


Definition at line 427 of file hardware/driver/icm20689/inc/sl_icm20689.h