ICM20689 - Motion Sensor

Description

Driver for the Invensense ICM20689 6-axis motion sensor.

Modules

Register definitions
Register definitions.
 

Functions

sl_status_t sl_icm20689_spi_init (void)
 Initialize the SPI bus to communicate with the ICM20689.
 
sl_status_t sl_icm20689_deinit (void)
 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 sl_icm20689_reset (void)
 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 sl_icm20689_init (void)
 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 sl_icm20689_accel_read_data (float accel[3])
 Read the raw acceleration value and convert to g value based on the actual resolution.
 
sl_status_t sl_icm20689_gyro_read_data (float gyro[3])
 Read the raw gyroscope value and convert to deg/sec value based on the actual resolution.
 
sl_status_t sl_icm20689_accel_get_resolution (float *accel_res)
 Get the actual resolution of the accelerometer.
 
sl_status_t sl_icm20689_gyro_get_resolution (float *gyro_res)
 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 sl_icm20689_enable_sleep_mode (bool enable)
 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 sl_icm20689_is_data_ready (void)
 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 sl_icm20689_read_temperature_data (float *temperature)
 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.

Returns
Returns zero on OK, non-zero otherwise

◆ sl_icm20689_deinit()

sl_status_t sl_icm20689_deinit ( void  )

De-initialize the ICM20689 sensor.

Returns
Returns zero on OK, non-zero otherwise

◆ 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]addrThe register address to read from in the sensor Bit[7:0] - register address
[in]num_bytesThe number of bytes to read
[out]dataThe data read from the register
Returns
Returns zero on OK, non-zero otherwise

◆ 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]addrThe register address to write Bit[7:0] - register address
[in]dataThe data to write to the register
Returns
Returns zero on OK, non-zero otherwise

◆ sl_icm20689_reset()

sl_status_t sl_icm20689_reset ( void  )

Perform soft reset on the ICM20689 chip.

Returns
Returns zero on OK, non-zero otherwise

◆ 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_rateThe 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.

◆ sl_icm20689_init()

sl_status_t sl_icm20689_init ( void  )

Initialize the ICM20689 sensor.

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

◆ 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_bandwidthThe 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

◆ 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_bandwidthThe 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

◆ sl_icm20689_accel_read_data()

sl_status_t sl_icm20689_accel_read_data ( float  accel[3])

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

Parameters
[out]accelA 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

◆ sl_icm20689_gyro_read_data()

sl_status_t sl_icm20689_gyro_read_data ( float  gyro[3])

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

Parameters
[out]gyroA 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

◆ 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_resThe resolution in g/bit units
Returns
Returns zero on OK, non-zero otherwise

◆ 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_resThe actual resolution in (deg/sec)/bit units
Returns
Returns zero on OK, non-zero otherwise

◆ 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_fsThe desired full scale value. The value of x can be 2, 4, 8 or 16.
Returns
Returns zero on OK, non-zero otherwise

◆ 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_fsThe desired full scale value. The value of y can be 250, 500, 1000 or 2000.
Returns
Returns zero on OK, non-zero otherwise

◆ 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]enableIf true, sleep mode is enabled. Set to false to disable sleep mode.
Returns
Returns zero on OK, non-zero otherwise

◆ 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]accelIf true, enables the acceleration sensor
[in]gyroIf true, enables the gyroscope sensor
[in]tempIf true, enables the temperature sensor
Returns
Returns zero on OK, non-zero otherwise

◆ 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_enableIf true, enables the Raw Data Ready interrupt, otherwise disables.
[in]wom_enableIf true, enables the Wake-up On Motion interrupt, otherwise disables.
Returns
Returns zero on OK, non-zero otherwise

◆ 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_statusThe content the four interrupt registers. LSByte is INT_STATUS, MSByte is INT_STATUS_3
Returns
Returns zero on OK, non-zero otherwise

◆ sl_icm20689_is_data_ready()

bool sl_icm20689_is_data_ready ( void  )

Check if new data is available to read.

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

◆ 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.

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.

Parameters
[out]accel_bias_scaledThe mesured acceleration sensor bias in mg
[out]gyro_bias_scaledThe mesured gyro sensor bias in deg/sec
Returns
Returns zero on OK, non-zero otherwise

◆ sl_icm20689_calibrate_gyro()

sl_status_t sl_icm20689_calibrate_gyro ( float *  gyro_bias_scaled)

Gyroscope calibration function.

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.

Parameters
[out]gyro_bias_scaledThe mesured gyro sensor bias in deg/sec
Returns
Returns zero on OK, non-zero otherwise

◆ 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]temperatureThe mesured temperature in Celsius
Returns
Returns zero on OK, non-zero otherwise

◆ 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_idThe ID of the device read from the WHO_AM_I register. Expected value 0x98.
Returns
Returns zero on OK, non-zero otherwise