ICM40627 - Motion Sensor#

Driver for the Invensense ICM40627 6-axis motion sensor.

Modules#

Register definitions

Functions#

sl_status_t

Initialize the SPI bus to communicate with the ICM40627.

sl_status_t

De-initialize the ICM40627 sensor.

sl_status_t
sl_icm40627_read_register(uint16_t addr, int num_bytes, uint8_t *data)

Read register from the ICM40627 device.

sl_status_t
sl_icm40627_write_register(uint16_t addr, uint8_t data)

Write a register in the ICM40627 device.

sl_status_t

Perform soft reset on the ICM40627 chip.

sl_status_t

Initialize the ICM40627 sensor.

sl_status_t
sl_icm40627_gyro_set_bandwidth(sl_gyro_BW_t gyro_Bw)

Set the bandwidth of the gyroscope.

sl_status_t
sl_icm40627_accel_set_bandwidth(sl_accel_BW_t accel_Bw)

Set the bandwidth of the accelerometer.

float
sl_icm40627_set_sample_rate(float sample_rate)

Set the sample rate(Output Data Rate) for both the accelerometer and the gyroscope.

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.

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.

sl_status_t

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

sl_status_t

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

sl_status_t

Get the actual resolution of the accelerometer.

sl_status_t

Get the actual resolution of the gyroscope.

sl_status_t
sl_icm40627_accel_set_full_scale(sl_Accel_FS_t accelFs)

Set the Full scale value of the accelerometer.

sl_status_t
sl_icm40627_gyro_set_full_scale(sl_gyro_FS_t gyroFs)

Set the full scale value of the gyroscope.

sl_status_t

Enable or disable the sleep mode of the device.

sl_status_t
sl_icm40627_enable_sensor(bool accel, bool gyro, bool temp)

Enable or disable the sensors in the ICM40627 chip.

sl_status_t
sl_icm40627_enable_interrupt(bool data_ready_enable, bool wom_enable)

Enable or disable the interrupts in the ICM40627 chip.

sl_status_t
sl_icm40627_read_interrupt_status(uint32_t *int_status)

Read the interrupt status registers of the ICM40627 chip.

bool

Check if new data is available to read.

sl_status_t
sl_icm40627_calibrate_accel_and_gyro(float *accel_bias_scaled, float *gyro_bias_scaled)

Accelerometer and gyroscope calibration function.

sl_status_t

Read the temperature sensor raw value and convert to Celsius.

sl_status_t
sl_icm40627_get_device_id(uint8_t *dev_id)

Read the device ID of the ICM40627.

sl_status_t
sl_icm40627_calibrate_gyro(float *gyroBiasScaled)

Gyroscope calibration function.

sl_status_t

Enable or disable the accelerometer sensor in low-power mode in the ICM40627 chip.

sl_status_t

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.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
N/A

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 205 of file hardware/driver/icm40627/inc/sl_icm40627.h

sl_icm40627_init#

sl_status_t sl_icm40627_init (void )

Initialize the ICM40627 sensor.

Parameters
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


Definition at line 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.

Parameters
[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


Definition at line 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.

Parameters
[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


Definition at line 242 of file hardware/driver/icm40627/inc/sl_icm40627.h

sl_icm40627_set_sample_rate#

float sl_icm40627_set_sample_rate (float sample_rate)

Set the sample rate(Output Data Rate) for both the accelerometer and the gyroscope.

Parameters
[in]sample_rate

The desired sample rate in Hz. The value of the sample_rate can be 8000Hz, 4000Hz, 2000Hz, 1000Hz, 500Hz, 200Hz, 100Hz, 50Hz, 25Hz, 12Hz.

Returns

  • Returns the actual sample rate.


Definition at line 257 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.

Parameters
[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


Definition at line 272 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.

Parameters
[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


Definition at line 287 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.

Parameters
[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


Definition at line 301 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.

Parameters
[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


Definition at line 315 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.

Parameters
[out]accel_res

The resolution in g/bit units

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 327 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.

Parameters
[out]gyro_res

The actual resolution in (deg/sec)/bit units

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 339 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.

Parameters
[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


Definition at line 353 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.

Parameters
[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


Definition at line 367 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.

Parameters
[in]enable

If true, sleep mode is enabled. Set to false to disable sleep mode.

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 379 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.

Parameters
[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


Definition at line 397 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.

Parameters
[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


Definition at line 412 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.

Parameters
[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


Definition at line 425 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.

Parameters
N/A

Returns

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


Definition at line 434 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.

Parameters
[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


Definition at line 452 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.

Parameters
[out]temperature

The mesured temperature in Celsius

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 464 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.

Parameters
[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


Definition at line 476 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.

Parameters
[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


Definition at line 491 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.

Parameters
[in]enAccel

If true, enables the acceleration sensor in low power mode

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 503 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.

Parameters
[in]bank

The address of the register bank (0,1,2,4)

Returns

  • Returns zero on OK, non-zero otherwise


Definition at line 515 of file hardware/driver/icm40627/inc/sl_icm40627.h