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.
N/A |
Returns
Returns zero on OK, non-zero otherwise
299
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_read_register#
void sl_icm20648_read_register (uint16_t addr, int numBytes, uint8_t * data)
Read register from the ICM20648 device.
[in] | addr | The register address to read from in the sensor Bit[8:7] - bank address Bit[6:0] - register address |
[in] | numBytes | The number of bytes to read |
[out] | data | The data read from the register |
316
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_write_register#
void sl_icm20648_write_register (uint16_t addr, uint8_t data)
Write a register in the ICM20648 device.
[in] | addr | The register address to write Bit[8:7] - bank address Bit[6:0] - register address |
[in] | data | The data to write to the register |
330
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_select_register_bank#
void sl_icm20648_select_register_bank (uint8_t bank)
Select the desired register bank.
[in] | bank | The address of the register bank (0..3) |
339
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_reset#
sl_status_t sl_icm20648_reset (void )
Perform soft reset on the ICM20648 chip.
N/A |
Returns
Returns zero on OK, non-zero otherwise
348
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
362
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_gyro_set_sample_rate#
float sl_icm20648_gyro_set_sample_rate (float sampleRate)
Set the sample rate of the accelerometer.
[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.
375
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_accel_set_sample_rate#
float sl_icm20648_accel_set_sample_rate (float sampleRate)
Set the sample rate of the gyroscope.
[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.
388
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_gyro_set_bandwidth#
sl_status_t sl_icm20648_gyro_set_bandwidth (uint8_t gyroBw)
Set the bandwidth of the gyroscope.
[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
402
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_accel_set_bandwidth#
sl_status_t sl_icm20648_accel_set_bandwidth (uint8_t accelBw)
Set the bandwidth of the accelerometer.
[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
416
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
430
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
444
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_accel_get_resolution#
sl_status_t sl_icm20648_accel_get_resolution (float * accelRes)
Get the actual resolution of the accelerometer.
[out] | accelRes | The resolution in g/bit units |
Returns
Returns zero on OK, non-zero otherwise
456
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_gyro_get_resolution#
sl_status_t sl_icm20648_gyro_get_resolution (float * gyroRes)
Get the actual resolution of the gyroscope.
[out] | gyroRes | The actual resolution in (deg/sec)/bit units |
Returns
Returns zero on OK, non-zero otherwise
468
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
482
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
496
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_enable_sleep_mode#
sl_status_t sl_icm20648_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
508
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
521
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
539
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[in] | enAccel | If true, enables the acceleration sensor in low power mode |
[in] | enGyro | If true, enables the gyroscope sensor in low power mode |
[in] | enTemp | If true, enables the temperature sensor in low power mode |
Returns
Returns zero on OK, non-zero otherwise
557
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_enable_interrupt#
sl_status_t sl_icm20648_enable_interrupt (bool dataReadyEnable, bool womEnable)
Enable or disable the interrupts in the ICM20648 chip.
[in] | dataReadyEnable | If true, enables the Raw Data Ready interrupt, otherwise disables. |
[in] | womEnable | If true, enables the Wake-up On Motion interrupt, otherwise disables. |
Returns
Returns zero on OK, non-zero otherwise
572
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[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
585
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_is_data_ready#
bool sl_icm20648_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
594
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[in] | enable | If true enables the WOM feature, disables otherwise |
[in] | womThreshold | Threshold value for the Wake on Motion Interrupt for ACCEL x/y/z axes. LSB = 4mg. Range is 0mg to 1020mg |
[in] | sampleRate | The desired sample rate of the accel sensor in Hz |
Returns
Returns zero on OK, non-zero otherwise
613
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_init#
sl_status_t sl_icm20648_init (void )
Initialize the ICM20648 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
624
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_deinit#
sl_status_t sl_icm20648_deinit (void )
De-initialize the ICM20648 sensor by disconnecting the supply and SPI lines.
N/A |
Returns
Returns zero on OK, non-zero otherwise
634
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_calibrate_accel_and_gyro#
sl_status_t sl_icm20648_calibrate_accel_and_gyro (float * accelBiasScaled, float * gyroBiasScaled)
Accelerometer and gyroscope calibration function.
[out] | accelBiasScaled | The mesured acceleration sensor bias in mg |
[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
652
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_calibrate_gyro#
sl_status_t sl_icm20648_calibrate_gyro (float * gyroBiasScaled)
Gyroscope calibration function.
[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
667
of file hardware/driver/icm20648/inc/sl_icm20648.h
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.
[out] | temperature | The mesured temperature in Celsius |
Returns
Returns zero on OK, non-zero otherwise
679
of file hardware/driver/icm20648/inc/sl_icm20648.h
sl_icm20648_get_device_id#
sl_status_t sl_icm20648_get_device_id (uint8_t * devID)
Read the device ID of the ICM20648.
[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
691
of file hardware/driver/icm20648/inc/sl_icm20648.h