ICM20648 - Motion Sensor#
Driver for the Invensense ICM20648 6-axis motion sensor.
Modules#
Functions#
Initialize the SPI bus to communicate with the ICM20648.
Read register from the ICM20648 device.
Write a register in the ICM20648 device.
Select the desired register bank.
Perform soft reset on the ICM20648 chip.
Set the sample rate both of the accelerometer and the gyroscope.
Set the sample rate of the accelerometer.
Set the sample rate of the gyroscope.
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 cycle mode operation of the accel and gyro.
Enable or disable the sensors in the ICM20648 chip.
Enable or disable sensors in low-power mode in the ICM20648 chip.
Enable or disable the interrupts in the ICM20648 chip.
Read the interrupt status registers of the ICM20648 chip.
Check if new data is available to read.
Set up and enable the Wake-up On Motion feature.
Initialize the ICM20648 sensor.
De-initialize the ICM20648 sensor by disconnecting the supply and SPI lines.
Accelerometer and gyroscope calibration function.
Gyroscope calibration function.
Read the temperature sensor raw value and convert to Celsius.
Read the device ID of the ICM20648.
Function Documentation#
sl_icm20648_spi_init#
sl_status_t sl_icm20648_spi_init (void )
Initialize the SPI bus to communicate with the ICM20648.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_read_register#
void sl_icm20648_read_register (uint16_t addr, int numBytes, uint8_t * data)
Read register from the ICM20648 device.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint16_t | [in] | addr | The register address to read from in the sensor Bit[8:7] - bank address Bit[6:0] - register address |
int | [in] | numBytes | The number of bytes to read |
uint8_t * | [out] | data | The data read from the register |
sl_icm20648_write_register#
void sl_icm20648_write_register (uint16_t addr, uint8_t data)
Write a register in the ICM20648 device.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint16_t | [in] | addr | The register address to write Bit[8:7] - bank address Bit[6:0] - register address |
uint8_t | [in] | data | The data to write to the register |
sl_icm20648_select_register_bank#
void sl_icm20648_select_register_bank (uint8_t bank)
Select the desired register bank.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | bank | The address of the register bank (0..3) |
sl_icm20648_reset#
sl_status_t sl_icm20648_reset (void )
Perform soft reset on the ICM20648 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_set_sample_rate#
sl_status_t sl_icm20648_set_sample_rate (float sampleRate)
Set the sample rate both of the accelerometer and the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
float | [in] | sampleRate | The desired sample rate in Hz. Because the resolution of the sample rate divider is different in the accel and gyro stages, two sensors may have a different sample rate set. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_gyro_set_sample_rate#
float sl_icm20648_gyro_set_sample_rate (float sampleRate)
Set the sample rate of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
float | [in] | sampleRate | 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.
sl_icm20648_accel_set_sample_rate#
float sl_icm20648_accel_set_sample_rate (float sampleRate)
Set the sample rate of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
float | [in] | sampleRate | 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.
sl_icm20648_gyro_set_bandwidth#
sl_status_t sl_icm20648_gyro_set_bandwidth (uint8_t gyroBw)
Set the bandwidth of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | gyroBw | The desired bandwidth value. Use the ICM20648_GYRO_BW_xHZ macros, which are defined in the icm20648.h file. The value of x can be 6, 12, 24, 51, 120, 150, 200, 360 or 12100. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_accel_set_bandwidth#
sl_status_t sl_icm20648_accel_set_bandwidth (uint8_t accelBw)
Set the bandwidth of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | accelBw | The desired bandwidth value. Use the ICM20648_ACCEL_BW_yHZ macros, which are defined in the icm20648.h file. The value of y can be 6, 12, 24, 50, 111, 246, 470 or 1210. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_accel_read_data#
sl_status_t sl_icm20648_accel_read_data (float * accel)
Read the raw acceleration value and convert to g value based on the actual resolution.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [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
sl_icm20648_gyro_read_data#
sl_status_t sl_icm20648_gyro_read_data (float * gyro)
Read the raw gyroscope value and convert to deg/sec value based on the actual resolution.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [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
sl_icm20648_accel_get_resolution#
sl_status_t sl_icm20648_accel_get_resolution (float * accelRes)
Get the actual resolution of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | accelRes | The resolution in g/bit units |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_gyro_get_resolution#
sl_status_t sl_icm20648_gyro_get_resolution (float * gyroRes)
Get the actual resolution of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | gyroRes | The actual resolution in (deg/sec)/bit units |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_accel_set_full_scale#
sl_status_t sl_icm20648_accel_set_full_scale (uint8_t accelFs)
Set the full scale value of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | accelFs | The desired full scale value. Use the ICM20648_ACCEL_FULLSCALE_xG macros, which are defined in the icm20648.h file. The value of x can be 2, 4, 8 or 16. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_gyro_set_full_scale#
sl_status_t sl_icm20648_gyro_set_full_scale (uint8_t gyroFs)
Set the full scale value of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | gyroFs | The desired full scale value. Use the ICM20648_GYRO_FULLSCALE_yDPS macros, which are defined in the icm20648.h file. The value of y can be 250, 500, 1000 or 2000. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_enable_sleep_mode#
sl_status_t sl_icm20648_enable_sleep_mode (bool enable)
Enable or disable the sleep mode of the device.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | enable | If true, sleep mode is enabled. Set to false to disable sleep mode. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_enable_cycle_mode#
sl_status_t sl_icm20648_enable_cycle_mode (bool enable)
Enable or disable the cycle mode operation of the accel and gyro.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | enable | If true both the accel and gyro sensors will operate in cycle mode. If false the senors working in continuous mode. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_enable_sensor#
sl_status_t sl_icm20648_enable_sensor (bool accel, bool gyro, bool temp)
Enable or disable the sensors in the ICM20648 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | accel | If true, enables the acceleration sensor |
bool | [in] | gyro | If true, enables the gyroscope sensor |
bool | [in] | temp | If true, enables the temperature sensor |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_enter_low_power_mode#
sl_status_t sl_icm20648_enter_low_power_mode (bool enAccel, bool enGyro, bool enTemp)
Enable or disable sensors in low-power mode in the ICM20648 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | enAccel | If true, enables the acceleration sensor in low power mode |
bool | [in] | enGyro | If true, enables the gyroscope sensor in low power mode |
bool | [in] | enTemp | If true, enables the temperature sensor in low power mode |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_enable_interrupt#
sl_status_t sl_icm20648_enable_interrupt (bool dataReadyEnable, bool womEnable)
Enable or disable the interrupts in the ICM20648 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | dataReadyEnable | If true, enables the Raw Data Ready interrupt, otherwise disables. |
bool | [in] | womEnable | If true, enables the Wake-up On Motion interrupt, otherwise disables. |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_read_interrupt_status#
sl_status_t sl_icm20648_read_interrupt_status (uint32_t * int_status)
Read the interrupt status registers of the ICM20648 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t * | [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
sl_icm20648_is_data_ready#
bool sl_icm20648_is_data_ready (void )
Check if new data is available to read.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Returns true if the Raw Data Ready interrupt bit set, false otherwise
sl_icm20648_enable_wake_on_motion_interrupt#
sl_status_t sl_icm20648_enable_wake_on_motion_interrupt (bool enable, uint8_t womThreshold, float sampleRate)
Set up and enable the Wake-up On Motion feature.
Type | Direction | Argument Name | Description |
---|---|---|---|
bool | [in] | enable | If true enables the WOM feature, disables otherwise |
uint8_t | [in] | womThreshold | Threshold value for the Wake on Motion Interrupt for ACCEL x/y/z axes. LSB = 4mg. Range is 0mg to 1020mg |
float | [in] | sampleRate | The desired sample rate of the accel sensor in Hz |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_init#
sl_status_t sl_icm20648_init (void )
Initialize the ICM20648 sensor.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | 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
sl_icm20648_deinit#
sl_status_t sl_icm20648_deinit (void )
De-initialize the ICM20648 sensor by disconnecting the supply and SPI lines.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_calibrate_accel_and_gyro#
sl_status_t sl_icm20648_calibrate_accel_and_gyro (float * accelBiasScaled, float * gyroBiasScaled)
Accelerometer and gyroscope calibration function.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | accelBiasScaled | The mesured acceleration sensor bias in mg |
float * | [out] | gyroBiasScaled | 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
sl_icm20648_calibrate_gyro#
sl_status_t sl_icm20648_calibrate_gyro (float * gyroBiasScaled)
Gyroscope calibration function.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | gyroBiasScaled | 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
sl_icm20648_read_temperature_data#
sl_status_t sl_icm20648_read_temperature_data (float * temperature)
Read the temperature sensor raw value and convert to Celsius.
Type | Direction | Argument Name | Description |
---|---|---|---|
float * | [out] | temperature | The mesured temperature in Celsius |
Returns
Returns zero on OK, non-zero otherwise
sl_icm20648_get_device_id#
sl_status_t sl_icm20648_get_device_id (uint8_t * devID)
Read the device ID of the ICM20648.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t * | [out] | devID | The ID of the device read from the WHO_AM_I register. Expected value 0xE0. |
Returns
Returns zero on OK, non-zero otherwise