ICM40627 Motion Sensor#
Introduction#
The ICM40627 motion sensor driver provides a set of functions for interacting with the ICM40627 6-axis motion sensor over the SPI interface. It enables integration of the sensor by offering APIs for initialization, configuration, data acquisition, and calibration. The driver supports reading acceleration, gyroscope, and temperature data, as well as configuring output data rates, full-scale ranges, and interrupt handling.
Usage#
After initializing the SSI (SPI) peripheral and configuring the ICM40627 sensor, the following common operations are available:
Initialize the ICM40627 sensor:sl_si91x_icm40627_init
Read the device ID to verify sensor presence:sl_si91x_icm40627_get_device_id
Read acceleration data (in g):sl_si91x_icm40627_get_accel_data
Read gyroscope data (in deg/sec):sl_si91x_icm40627_get_gyro_data
Read temperature data (in Celsius):sl_si91x_icm40627_get_temperature_data
Set output data rates and bandwidths for accelerometer and gyroscope:sl_si91x_icm40627_set_sample_rate, sl_si91x_icm40627_set_accel_bandwidth, sl_si91x_icm40627_set_gyro_bandwidth
Configure full-scale ranges for accelerometer and gyroscope:sl_si91x_icm40627_set_accel_full_scale, sl_si91x_icm40627_set_gyro_full_scale
Enable or disable sensor interrupts:sl_si91x_icm40627_enable_interrupt
Calibrate accelerometer and gyroscope biases:sl_si91x_icm40627_calibrate_accel_and_gyro
Typical usage sequence:
Initialize the sensor: Use sl_si91x_icm40627_init before other operations.
Verify sensor presence: Optionally read the device ID using sl_si91x_icm40627_get_device_id.
Configure sensor settings: Set sample rates, bandwidths, and full-scale ranges as needed.
Enable required interrupts: Use sl_si91x_icm40627_enable_interrupt to configure interrupt sources.
Read sensor data: Use sl_si91x_icm40627_get_accel_data, sl_si91x_icm40627_get_gyro_data, and sl_si91x_icm40627_get_temperature_data to acquire measurements.
Calibrate sensors if necessary: Use sl_si91x_icm40627_calibrate_accel_and_gyro for bias correction.
See the Function Documentation for detailed usage information of all APIs.
Functions#
Select the desired Register bank.
Perform soft reset on the ICM40627 chip.
Set the bandwidth of the gyroscope.
Set the bandwidth of the accelerometer.
Enable or disable the sleep mode of the ICM40627 device.
Sets the sample rate for both the accelerometer and the gyroscope.
Set the sample rate(Output Data Rate) of the accelerometer.
Set the sample rate(Output Data Rate) of the gyroscope.
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 interrupts in the ICM40627 chip.
Read the interrupt status registers of the ICM40627 chip.
Check if new data is available to read.
Enable or disable the sensors in the ICM40627 chip.
Initialize the ICM40627 sensor.
De-initialize the ICM40627 sensor by disconnecting the supply and SPI lines.
Accelerometer and gyroscope calibration function.
Read the temperature sensor raw value and convert to Celsius.
Read the device ID of the ICM40627.
Function Documentation#
icm40627_select_register_bank#
sl_status_t icm40627_select_register_bank (sl_ssi_handle_t ssi_driver_handle, uint8_t bank)
Select the desired Register bank.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | bank | The address of the Register bank (0..3) |
sl_si91x_icm40627_software_reset#
sl_status_t sl_si91x_icm40627_software_reset (sl_ssi_handle_t ssi_driver_handle)
Perform soft reset on the ICM40627 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_set_gyro_bandwidth#
sl_status_t sl_si91x_icm40627_set_gyro_bandwidth (sl_ssi_handle_t ssi_driver_handle, uint8_t gyro_ODR)
Set the bandwidth of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | gyro_ODR | The desired ODR value. Use the ICM40627_GYRO_BW_xHZ macros, which are defined in the icm40627.h file. The value of x can be 6, 12, 24, 51, 120, 150, 200, 360 or 12100. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_set_accel_bandwidth#
sl_status_t sl_si91x_icm40627_set_accel_bandwidth (sl_ssi_handle_t ssi_driver_handle, uint8_t accel_ODR)
Set the bandwidth of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | accel_ODR | The desired ODR value. Use the ICM40627_ACCEL_BW_yHZ macros, which are defined in the icm40627.h file. The value of y can be 6, 12, 24, 50, 111, 246, 470 or 1210. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_enable_sleep_mode#
sl_status_t sl_si91x_icm40627_enable_sleep_mode (sl_ssi_handle_t ssi_driver_handle, bool enable)
Enable or disable the sleep mode of the ICM40627 device.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor. |
bool | [in] | enable | If true, sleep mode is enabled to reduce power consumption by disabling the accelerometer and gyroscope while retaining essential functions for quick wake-up. Set to false to disable sleep mode and resume normal operation. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_set_sample_rate#
float sl_si91x_icm40627_set_sample_rate (sl_ssi_handle_t ssi_driver_handle, float sample_rate)
Sets the sample rate for both the accelerometer and the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor. |
float | [in] | sample_rate | The desired sample rate in Hz. The function will set the closest available sample rate to the requested value if an exact match is not possible. Available sample rates (in Hz) are:
|
The accelerometer supports rates down to 3.125 Hz, while the gyroscope supports rates down to 12.5 Hz. Requests below 12.5 Hz will set only the accelerometer rate, with the gyroscope defaulting to 12.5 Hz.
Returns
The actual sample rate set, which may differ from the requested rate due to available sample rate options.
sl_si91x_icm40627_accel_set_sample_rate#
sl_status_t sl_si91x_icm40627_accel_set_sample_rate (sl_ssi_handle_t ssi_driver_handle, uint8_t accel_ODR)
Set the sample rate(Output Data Rate) of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | accel_ODR | The desired sample rate value. Use the sl_accel_ODR_t enum, which are defined in the icm40627.h file. The value can be 8 kHz, 4 kHz, 2 kHz, 1 kHz, 500 Hz, 200 Hz, 100 Hz, 50 Hz 25 Hz, 12.5 Hz, 6.25 Hz, 3.125 Hz, 1.5625 Hz. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_gyro_set_sample_rate#
sl_status_t sl_si91x_icm40627_gyro_set_sample_rate (sl_ssi_handle_t ssi_driver_handle, uint8_t gyro_ODR)
Set the sample rate(Output Data Rate) of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | gyro_ODR | The desired sample rate value. Use the sl_gyro_ODR_t enum, which are defined in the icm40627.h file. The value can be 8 kHz, 4 kHz, 2 kHz, 1 kHz, 500 Hz, 200 Hz, 100 Hz, 50 Hz 25 Hz, 12.5 Hz. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_get_accel_data#
sl_status_t sl_si91x_icm40627_get_accel_data (sl_ssi_handle_t ssi_driver_handle, float accel)
Read the raw acceleration value and convert to g value based on the actual resolution.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
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
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_get_gyro_data#
sl_status_t sl_si91x_icm40627_get_gyro_data (sl_ssi_handle_t ssi_driver_handle, float gyro)
Read the raw gyroscope value and convert to deg/sec value based on the actual resolution.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
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
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_get_accel_resolution#
sl_status_t sl_si91x_icm40627_get_accel_resolution (sl_ssi_handle_t ssi_driver_handle, float * accel_res)
Get the actual resolution of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
float * | [out] | accel_res | The resolution in g/bit units |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_get_gyro_resolution#
sl_status_t sl_si91x_icm40627_get_gyro_resolution (sl_ssi_handle_t ssi_driver_handle, float * gyro_res)
Get the actual resolution of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
float * | [out] | gyro_res | The actual resolution in (deg/sec)/bit units |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_set_accel_full_scale#
sl_status_t sl_si91x_icm40627_set_accel_full_scale (sl_ssi_handle_t ssi_driver_handle, uint8_t accelFs)
Set the full scale value of the accelerometer.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | accelFs | The desired full scale value. Use the ICM40627_ACCEL_FULLSCALE_xG macros, which are defined in the icm40627.h file. The value of x can be 2, 4, 8 or 16. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_set_gyro_full_scale#
sl_status_t sl_si91x_icm40627_set_gyro_full_scale (sl_ssi_handle_t ssi_driver_handle, uint8_t accelFs)
Set the full scale value of the gyroscope.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t | [in] | accelFs | The desired full scale value. Use the ICM40627_GYRO_FULLSCALE_yDPS macros, which are defined in the icm40627.h file. The value of y can be 250, 500, 1000 or 2000. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_enable_interrupt#
sl_status_t sl_si91x_icm40627_enable_interrupt (sl_ssi_handle_t ssi_driver_handle, bool dataReadyEnable, bool womEnable)
Enable or disable the interrupts in the ICM40627 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
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
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_read_interrupt_status#
sl_status_t sl_si91x_icm40627_read_interrupt_status (sl_ssi_handle_t ssi_driver_handle, uint32_t * int_status)
Read the interrupt status registers of the ICM40627 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint32_t * | [out] | int_status | A 32-bit value that represents the combined status of the three interrupt registers: INT_STATUS, INT_STATUS2, and INT_STATUS3. Each bit in this value corresponds to a specific interrupt flag, as follows:
|
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_is_data_ready#
bool sl_si91x_icm40627_is_data_ready (sl_ssi_handle_t ssi_driver_handle)
Check if new data is available to read.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
Returns
Returns true if the Raw Data Ready interrupt bit is set, false otherwise.
sl_si91x_icm40627_enable_sensor#
sl_status_t sl_si91x_icm40627_enable_sensor (sl_ssi_handle_t ssi_driver_handle, bool accel, bool gyro, bool temp)
Enable or disable the sensors in the ICM40627 chip.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
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
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_init#
sl_status_t sl_si91x_icm40627_init (sl_ssi_handle_t ssi_driver_handle)
Initialize the ICM40627 sensor.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 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
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_deinit#
sl_status_t sl_si91x_icm40627_deinit (void )
De-initialize the ICM40627 sensor by disconnecting the supply and SPI lines.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_calibrate_accel_and_gyro#
sl_status_t sl_si91x_icm40627_calibrate_accel_and_gyro (sl_ssi_handle_t ssi_driver_handle, float * accel_bias_scaled, float * gyro_bias_scaled)
Accelerometer and gyroscope calibration function.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
float * | [out] | accel_bias_scaled | The mesured acceleration sensor bias in mg |
float * | [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
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_get_temperature_data#
sl_status_t sl_si91x_icm40627_get_temperature_data (sl_ssi_handle_t ssi_driver_handle, float * temp_data)
Read the temperature sensor raw value and convert to Celsius.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
float * | [out] | temp_data | The mesured temperature in Celsius |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_icm40627_get_device_id#
sl_status_t sl_si91x_icm40627_get_device_id (sl_ssi_handle_t ssi_driver_handle, uint8_t * dev_id)
Read the device ID of the ICM40627.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_ssi_handle_t | [in] | ssi_driver_handle | The handle to the SSI driver used for communication with the ICM40627 sensor |
uint8_t * | [out] | dev_id | The ID of the device read from the WHO_AM_I Register. Expected value 0xE0. |
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Success.
SL_STATUS_INVALID_PARAMETER - The parameter is an invalid argument.
For more information on status codes, see SL STATUS DOCUMENTATION.