ICM20648 - Motion Sensor

Description

Driver for the Invensense ICM20648 6-axis motion sensor.

Modules

Register definitions
Register definitions.

Functions

sl_status_t sl_icm20648_spi_init (void)
Initialize the SPI bus to communicate with the ICM20648.
void sl_icm20648_read_register (uint16_t addr, int numBytes, uint8_t *data)
Read register from the ICM20648 device.
void sl_icm20648_write_register (uint16_t addr, uint8_t data)
Write a register in the ICM20648 device.
void sl_icm20648_select_register_bank (uint8_t bank)
Select the desired register bank.
sl_status_t sl_icm20648_reset (void)
Perform soft reset on the ICM20648 chip.
sl_status_t sl_icm20648_set_sample_rate (float sampleRate)
Set the sample rate both of the accelerometer and the gyroscope.
float sl_icm20648_gyro_set_sample_rate (float sampleRate)
Set the sample rate of the accelerometer.
float sl_icm20648_accel_set_sample_rate (float sampleRate)
Set the sample rate of the gyroscope.
sl_status_t sl_icm20648_gyro_set_bandwidth (uint8_t gyroBw)
Set the bandwidth of the gyroscope.
sl_status_t sl_icm20648_accel_set_bandwidth (uint8_t accelBw)
Set the bandwidth of the accelerometer.
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.
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.
sl_status_t sl_icm20648_accel_get_resolution (float *accelRes)
Get the actual resolution of the accelerometer.
sl_status_t sl_icm20648_gyro_get_resolution (float *gyroRes)
Get the actual resolution of the gyroscope.
sl_status_t sl_icm20648_accel_set_full_scale (uint8_t accelFs)
Set the full scale value of the accelerometer.
sl_status_t sl_icm20648_gyro_set_full_scale (uint8_t gyroFs)
Set the full scale value of the gyroscope.
sl_status_t sl_icm20648_enable_sleep_mode (bool enable)
Enable or disable the sleep mode of the device.
sl_status_t sl_icm20648_enable_cycle_mode (bool enable)
Enable or disable the cycle mode operation of the accel and gyro.
sl_status_t sl_icm20648_enable_sensor (bool accel, bool gyro, bool temp)
Enable or disable the sensors in the ICM20648 chip.
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.
sl_status_t sl_icm20648_enable_interrupt (bool dataReadyEnable, bool womEnable)
Enable or disable the interrupts in the ICM20648 chip.
sl_status_t sl_icm20648_read_interrupt_status (uint32_t *int_status)
Read the interrupt status registers of the ICM20648 chip.
bool sl_icm20648_is_data_ready (void)
Check if new data is available to read.
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.
sl_status_t sl_icm20648_init (void)
Initialize the ICM20648 sensor.
sl_status_t sl_icm20648_deinit (void)
De-initialize the ICM20648 sensor by disconnecting the supply and SPI lines.
sl_status_t sl_icm20648_calibrate_accel_and_gyro (float *accelBiasScaled, float *gyroBiasScaled)
Accelerometer and gyroscope calibration function.
sl_status_t sl_icm20648_calibrate_gyro (float *gyroBiasScaled)
Gyroscope calibration function.
sl_status_t sl_icm20648_read_temperature_data (float *temperature)
Read the temperature sensor raw value and convert to Celsius.
sl_status_t sl_icm20648_get_device_id (uint8_t *devID)
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.

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.

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

sl_icm20648_write_register()

void sl_icm20648_write_register ( uint16_t addr,
uint8_t data
)

Write a register in the ICM20648 device.

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

sl_icm20648_select_register_bank()

void sl_icm20648_select_register_bank ( uint8_t bank )

Select the desired register bank.

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

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.

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

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

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

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

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

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

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.

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

sl_icm20648_accel_get_resolution()

sl_status_t sl_icm20648_accel_get_resolution ( float * accelRes )

Get the actual resolution of the accelerometer.

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

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

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

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

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

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

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

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.

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

sl_icm20648_enable_interrupt()

sl_status_t sl_icm20648_enable_interrupt ( bool dataReadyEnable,
bool womEnable
)

Enable or disable the interrupts in the ICM20648 chip.

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

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.

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

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.

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

sl_icm20648_init()

sl_status_t sl_icm20648_init ( void )

Initialize the ICM20648 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
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.

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.

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.

Parameters
[out] accelBiasScaled The mesured acceleration sensor bias in mg
[out] gyroBiasScaled The mesured gyro sensor bias in deg/sec
Returns
Returns zero on OK, non-zero otherwise

sl_icm20648_calibrate_gyro()

sl_status_t sl_icm20648_calibrate_gyro ( float * gyroBiasScaled )

Gyroscope calibration function.

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.

Parameters
[out] gyroBiasScaled The mesured gyro sensor bias in deg/sec
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.

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

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