ICM40627 - Motion Sensor#
Driver for the Invensense ICM40627 6-axis motion sensor.
Modules#
Functions#
Initialize the SPI bus to communicate with the ICM40627.
De-initialize the ICM40627 sensor.
Read register from the ICM40627 device.
Write a register in the ICM40627 device.
Perform soft reset on the ICM40627 chip.
Initialize the ICM40627 sensor.
Set the bandwidth of the gyroscope.
Set the bandwidth of the accelerometer.
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 sleep mode of the device.
Enable or disable the sensors in the ICM40627 chip.
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.
Accelerometer and gyroscope calibration function.
Read the temperature sensor raw value and convert to Celsius.
Read the device ID of the ICM40627.
Gyroscope calibration function.
Enable or disable the accelerometer sensor in low-power mode in the ICM40627 chip.
Select the desired register bank.
Function Documentation#
sl_icm40627_spi_init#
sl_status_t sl_icm40627_spi_init (void )
Initialize the SPI bus to communicate with the ICM40627.
N/A |
Returns
Returns zero on OK, non-zero otherwise
152
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_deinit#
sl_status_t sl_icm40627_deinit (void )
De-initialize the ICM40627 sensor.
N/A |
Returns
Returns zero on OK, non-zero otherwise
161
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_read_register#
sl_status_t sl_icm40627_read_register (uint16_t addr, int num_bytes, uint8_t * data)
Read register from the ICM40627 device.
[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
180
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_write_register#
sl_status_t sl_icm40627_write_register (uint16_t addr, uint8_t data)
Write a register in the ICM40627 device.
[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
196
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_reset#
sl_status_t sl_icm40627_reset (void )
Perform soft reset on the ICM40627 chip.
N/A |
Returns
Returns zero on OK, non-zero otherwise
205
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_init#
sl_status_t sl_icm40627_init (void )
Initialize the ICM40627 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
216
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_gyro_set_bandwidth#
sl_status_t sl_icm40627_gyro_set_bandwidth (sl_gyro_BW_t gyro_Bw)
Set the bandwidth of the gyroscope.
[in] | gyro_Bw | The desired bandwidth value by chosing a UI filter Bandwidth mode. Use the sl_gyro_BW_t enum, which are defined in the icm40627.h file. |
Returns
Returns zero on OK, non-zero otherwise
229
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_accel_set_bandwidth#
sl_status_t sl_icm40627_accel_set_bandwidth (sl_accel_BW_t accel_Bw)
Set the bandwidth of the accelerometer.
[in] | accel_Bw | The desired bandwidth value by chosing a UI filter Bandwidth mode. Use the sl_accel_BW_t enum, which are defined in the icm40627.h file. |
Returns
Returns zero on OK, non-zero otherwise
242
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_set_sample_rate#
float sl_icm40627_set_sample_rate (float sample_rate)
Sets the sample rate for both the accelerometer and the gyroscope.
[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.
256
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_accel_set_sample_rate#
sl_status_t sl_icm40627_accel_set_sample_rate (sl_accel_ODR_t accel_ODR)
Set the sample rate(Output Data Rate) of the accelerometer.
[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
Returns zero on OK, non-zero otherwise
271
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_gyro_set_sample_rate#
sl_status_t sl_icm40627_gyro_set_sample_rate (sl_gyro_ODR_t gyro_ODR)
Set the sample rate(Output Data Rate) of the gyroscope.
[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
Returns zero on OK, non-zero otherwise
286
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_accel_read_data#
sl_status_t sl_icm40627_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
300
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_gyro_read_data#
sl_status_t sl_icm40627_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
314
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_accel_get_resolution#
sl_status_t sl_icm40627_accel_get_resolution (float * accel_res)
Get the actual resolution of the accelerometer.
[out] | accel_res | The resolution in g/bit units |
Returns
Returns zero on OK, non-zero otherwise
326
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_gyro_get_resolution#
sl_status_t sl_icm40627_gyro_get_resolution (float * gyro_res)
Get the actual resolution of the gyroscope.
[out] | gyro_res | The actual resolution in (deg/sec)/bit units |
Returns
Returns zero on OK, non-zero otherwise
338
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_accel_set_full_scale#
sl_status_t sl_icm40627_accel_set_full_scale (sl_Accel_FS_t accelFs)
Set the Full scale value of the accelerometer.
[in] | accelFs | The desired Full scale value. Use the sl_Accel_FS_t enum, which are defined in the icm40627.h file. The value can be 16g, 8g, 4g, 2g. |
Returns
Returns zero on OK, non-zero otherwise
352
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_gyro_set_full_scale#
sl_status_t sl_icm40627_gyro_set_full_scale (sl_gyro_FS_t gyroFs)
Set the full scale value of the gyroscope.
[in] | gyroFs | The desired full scale value. Use the sl_gyro_FS_t enum, which are defined in the icm40627.h file. The value can be 2000, 1000, 500, 250, 125, 62.5, 31.25, 15.625 (in dps). |
Returns
Returns zero on OK, non-zero otherwise
366
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_enable_sleep_mode#
sl_status_t sl_icm40627_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
378
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_enable_sensor#
sl_status_t sl_icm40627_enable_sensor (bool accel, bool gyro, bool temp)
Enable or disable the sensors in the ICM40627 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
396
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_enable_interrupt#
sl_status_t sl_icm40627_enable_interrupt (bool data_ready_enable, bool wom_enable)
Enable or disable the interrupts in the ICM40627 chip.
[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
411
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_read_interrupt_status#
sl_status_t sl_icm40627_read_interrupt_status (uint32_t * int_status)
Read the interrupt status registers of the ICM40627 chip.
[out] | int_status | The content of the three interrupt registers which are INT_STATUS, INT_STATUS2, INT_STATUS3. |
Returns
Returns zero on OK, non-zero otherwise
424
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_is_data_ready#
bool sl_icm40627_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
433
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_calibrate_accel_and_gyro#
sl_status_t sl_icm40627_calibrate_accel_and_gyro (float * accel_bias_scaled, float * gyro_bias_scaled)
Accelerometer and gyroscope calibration function.
[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
451
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_read_temperature_data#
sl_status_t sl_icm40627_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
463
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_get_device_id#
sl_status_t sl_icm40627_get_device_id (uint8_t * dev_id)
Read the device ID of the ICM40627.
[out] | dev_id | The ID of the device read from the WHO_AM_I register. Expected value 0x4E. |
Returns
Returns zero on OK, non-zero otherwise
475
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_calibrate_gyro#
sl_status_t sl_icm40627_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
490
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_accel_enter_low_power_mode#
sl_status_t sl_icm40627_accel_enter_low_power_mode (bool enAccel)
Enable or disable the accelerometer sensor in low-power mode in the ICM40627 chip.
[in] | enAccel | If true, enables the acceleration sensor in low power mode |
Returns
Returns zero on OK, non-zero otherwise
502
of file hardware/driver/icm40627/inc/sl_icm40627.h
sl_icm40627_select_register_bank#
sl_status_t sl_icm40627_select_register_bank (uint8_t bank)
Select the desired register bank.
[in] | bank | The address of the register bank (0,1,2,4) |
Returns
Returns zero on OK, non-zero otherwise
514
of file hardware/driver/icm40627/inc/sl_icm40627.h