EFM32 Zero Gecko Software Documentation  efm32zg-doc-5.1.2

Detailed Description

ICM20648 driver and support functions.

Functions

uint32_t ICM20648_accelBandwidthSet (uint8_t accelBw)
 Sets the bandwidth of the accelerometer. More...
 
uint32_t ICM20648_accelDataRead (float *accel)
 Reads the raw acceleration value and converts to g value based on the actual resolution. More...
 
uint32_t ICM20648_accelFullscaleSet (uint8_t accelFs)
 Sets the full scale value of the accelerometer. More...
 
uint32_t ICM20648_accelGyroCalibrate (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. More...
 
uint32_t ICM20648_accelResolutionGet (float *accelRes)
 Gets the actual resolution of the accelerometer. More...
 
float ICM20648_accelSampleRateSet (float sampleRate)
 Sets the sample rate of the gyroscope. More...
 
void ICM20648_bankSelect (uint8_t bank)
 Select the desired register bank. More...
 
uint32_t ICM20648_cycleModeEnable (bool enable)
 Enables or disables the cycle mode operation of the accel and gyro. More...
 
uint32_t ICM20648_deInit (void)
 De-initializes the ICM20648 sensor by disconnecting the supply and SPI lines. More...
 
uint32_t ICM20648_getDeviceID (uint8_t *devID)
 Reads the device ID of the ICM20648. More...
 
uint32_t ICM20648_gyroBandwidthSet (uint8_t gyroBw)
 Sets the bandwidth of the gyroscope. More...
 
uint32_t ICM20648_gyroCalibrate (float *gyroBiasScaled)
 Gyroscope calibration function. Reads 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. More...
 
uint32_t ICM20648_gyroDataRead (float *gyro)
 Reads the raw gyroscope value and converts to deg/sec value based on the actual resolution. More...
 
uint32_t ICM20648_gyroFullscaleSet (uint8_t gyroFs)
 Sets the full scale value of the gyroscope. More...
 
uint32_t ICM20648_gyroResolutionGet (float *gyroRes)
 Gets the actual resolution of the gyroscope. More...
 
float ICM20648_gyroSampleRateSet (float sampleRate)
 Sets the sample rate of the accelerometer. More...
 
uint32_t ICM20648_init (void)
 Initializes the ICM20648 sensor. Enables the power supply and SPI lines, sets up the host SPI controller, configures the chip control interface, clock generator and interrupt line. More...
 
uint32_t ICM20648_interruptEnable (bool dataReadyEnable, bool womEnable)
 Enables or disables the interrupts in the ICM20648 chip. More...
 
uint32_t ICM20648_interruptStatusRead (uint32_t *intStatus)
 Reads the interrupt status registers of the ICM20648 chip. More...
 
bool ICM20648_isDataReady (void)
 Checks if new data is available for read. More...
 
uint32_t ICM20648_lowPowerModeEnter (bool enAccel, bool enGyro, bool enTemp)
 Enables or disables the sensors in low power mode in the ICM20648 chip. More...
 
void ICM20648_registerRead (uint16_t addr, int numBytes, uint8_t *data)
 Reads register from the ICM20648 device. More...
 
void ICM20648_registerWrite (uint16_t addr, uint8_t data)
 Writes a register in the ICM20648 device. More...
 
uint32_t ICM20648_reset (void)
 Performs soft reset on the ICM20648 chip. More...
 
uint32_t ICM20648_sampleRateSet (float sampleRate)
 Sets the sample rate both of the accelerometer and the gyroscope. More...
 
uint32_t ICM20648_sensorEnable (bool accel, bool gyro, bool temp)
 Enables or disables the sensors in the ICM20648 chip. More...
 
uint32_t ICM20648_sleepModeEnable (bool enable)
 Enables or disables the sleep mode of the device. More...
 
uint32_t ICM20648_spiInit (void)
 Initializes the SPI bus in order to communicate with the ICM20648. More...
 
uint32_t ICM20648_temperatureRead (float *temperature)
 Reads the temperature sensor raw value and converts to Celsius. More...
 
uint32_t ICM20648_wakeOnMotionITEnable (bool enable, uint8_t womThreshold, float sampleRate)
 Sets up and enables the Wake-up On Motion feature. More...
 

Function Documentation

uint32_t ICM20648_accelBandwidthSet ( uint8_t  accelBw)

Sets the bandwidth of the accelerometer.

Parameters
[in]accelBwThe 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

Definition at line 491 of file icm20648.c.

References ICM20648_MASK_ACCEL_BW, ICM20648_OK, ICM20648_REG_ACCEL_CONFIG, ICM20648_registerRead(), and ICM20648_registerWrite().

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_wakeOnMotionITEnable(), and IMU_config().

uint32_t ICM20648_accelDataRead ( float *  accel)

Reads the raw acceleration value and converts to g value based on the actual resolution.

Parameters
[out]accelA 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 145 of file icm20648.c.

References ICM20648_accelResolutionGet(), ICM20648_OK, ICM20648_REG_ACCEL_XOUT_H_SH, and ICM20648_registerRead().

Referenced by IMU_getAccelerometerData().

uint32_t ICM20648_accelFullscaleSet ( uint8_t  accelFs)

Sets the full scale value of the accelerometer.

Parameters
[in]accelFsThe 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

Definition at line 305 of file icm20648.c.

References ICM20648_MASK_ACCEL_FULLSCALE, ICM20648_OK, ICM20648_REG_ACCEL_CONFIG, ICM20648_registerRead(), and ICM20648_registerWrite().

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_wakeOnMotionITEnable(), and IMU_config().

uint32_t ICM20648_accelGyroCalibrate ( float *  accelBiasScaled,
float *  gyroBiasScaled 
)
uint32_t ICM20648_accelResolutionGet ( float *  accelRes)

Gets the actual resolution of the accelerometer.

Parameters
[out]accelResThe resolution in g/bit units
Returns
Returns zero on OK, non-zero otherwise

Definition at line 217 of file icm20648.c.

References ICM20648_ACCEL_FULLSCALE_16G, ICM20648_ACCEL_FULLSCALE_2G, ICM20648_ACCEL_FULLSCALE_4G, ICM20648_ACCEL_FULLSCALE_8G, ICM20648_MASK_ACCEL_FULLSCALE, ICM20648_OK, ICM20648_REG_ACCEL_CONFIG, and ICM20648_registerRead().

Referenced by ICM20648_accelDataRead(), and ICM20648_accelGyroCalibrate().

float ICM20648_accelSampleRateSet ( float  sampleRate)

Sets the sample rate of the gyroscope.

Parameters
[in]sampleRateThe desired sample rate in Hz
Returns
The actual sample rate. May be different from the desired value because of the finite and discrete number of divider settings

Definition at line 420 of file icm20648.c.

References ICM20648_REG_ACCEL_SMPLRT_DIV_1, ICM20648_REG_ACCEL_SMPLRT_DIV_2, and ICM20648_registerWrite().

Referenced by ICM20648_sampleRateSet(), and IMU_config().

void ICM20648_bankSelect ( uint8_t  bank)

Select the desired register bank.

Parameters
[in]bankThe address of the register bank (0..3)
Returns
None

Definition at line 1407 of file icm20648.c.

References ICM20648_REG_BANK_SEL, USART_Rx(), and USART_Tx().

Referenced by ICM20648_registerRead(), and ICM20648_registerWrite().

uint32_t ICM20648_cycleModeEnable ( bool  enable)

Enables or disables the cycle mode operation of the accel and gyro.

Parameters
[in]enableIf 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

Definition at line 551 of file icm20648.c.

References ICM20648_BIT_ACCEL_CYCLE, ICM20648_BIT_GYRO_CYCLE, ICM20648_OK, ICM20648_REG_LP_CONFIG, and ICM20648_registerWrite().

Referenced by ICM20648_lowPowerModeEnter(), and ICM20648_wakeOnMotionITEnable().

uint32_t ICM20648_deInit ( void  )

De-initializes the ICM20648 sensor by disconnecting the supply and SPI lines.

Returns
Returns zero on OK, non-zero otherwise

Definition at line 103 of file icm20648.c.

References BOARD_imuEnable(), and ICM20648_OK.

Referenced by IMU_deInit(), and IMU_init().

uint32_t ICM20648_getDeviceID ( uint8_t *  devID)

Reads the device ID of the ICM20648.

Parameters
[out]devIDThe ID of the device read from teh WHO_AM_I register. Expected value? 0xE0
Returns
Returns zero on OK, non-zero otherwise

Definition at line 1256 of file icm20648.c.

References ICM20648_OK, ICM20648_REG_WHO_AM_I, and ICM20648_registerRead().

Referenced by IMU_init().

uint32_t ICM20648_gyroBandwidthSet ( uint8_t  gyroBw)

Sets the bandwidth of the gyroscope.

Parameters
[in]gyroBwThe 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

Definition at line 462 of file icm20648.c.

References ICM20648_MASK_GYRO_BW, ICM20648_OK, ICM20648_REG_GYRO_CONFIG_1, ICM20648_registerRead(), and ICM20648_registerWrite().

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_gyroCalibrate(), and IMU_config().

uint32_t ICM20648_gyroCalibrate ( float *  gyroBiasScaled)

Gyroscope calibration function. Reads 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]gyroBiasScaledThe mesured gyro sensor bias in deg/sec
Returns
Returns zero on OK, non-zero otherwise

Definition at line 1077 of file icm20648.c.

References ICM20648_BIT_FIFO_EN, ICM20648_BITS_GYRO_FIFO_EN, ICM20648_GYRO_BW_12HZ, ICM20648_GYRO_FULLSCALE_250DPS, ICM20648_gyroBandwidthSet(), ICM20648_gyroFullscaleSet(), ICM20648_gyroResolutionGet(), ICM20648_OK, ICM20648_REG_FIFO_COUNT_H, ICM20648_REG_FIFO_EN_2, ICM20648_REG_FIFO_MODE, ICM20648_REG_FIFO_R_W, ICM20648_REG_FIFO_RST, ICM20648_REG_USER_CTRL, ICM20648_REG_XG_OFFS_USRH, ICM20648_REG_XG_OFFS_USRL, ICM20648_REG_YG_OFFS_USRH, ICM20648_REG_YG_OFFS_USRL, ICM20648_REG_ZG_OFFS_USRH, ICM20648_REG_ZG_OFFS_USRL, ICM20648_registerRead(), ICM20648_registerWrite(), ICM20648_sampleRateSet(), ICM20648_sensorEnable(), and UTIL_delay().

Referenced by IMU_init().

uint32_t ICM20648_gyroDataRead ( float *  gyro)

Reads the raw gyroscope value and converts to deg/sec value based on the actual resolution.

Parameters
[out]gyroA 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 182 of file icm20648.c.

References ICM20648_gyroResolutionGet(), ICM20648_OK, ICM20648_REG_GYRO_XOUT_H_SH, and ICM20648_registerRead().

Referenced by IMU_getGyroData().

uint32_t ICM20648_gyroFullscaleSet ( uint8_t  gyroFs)

Sets the full scale value of the gyroscope.

Parameters
[in]gyroFsThe 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

Definition at line 332 of file icm20648.c.

References ICM20648_MASK_GYRO_FULLSCALE, ICM20648_OK, ICM20648_REG_GYRO_CONFIG_1, ICM20648_registerRead(), and ICM20648_registerWrite().

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_gyroCalibrate(), and IMU_config().

uint32_t ICM20648_gyroResolutionGet ( float *  gyroRes)

Gets the actual resolution of the gyroscope.

Parameters
[out]gyroResThe actual resolution in (deg/sec)/bit units
Returns
Returns zero on OK, non-zero otherwise

Definition at line 260 of file icm20648.c.

References ICM20648_GYRO_FULLSCALE_1000DPS, ICM20648_GYRO_FULLSCALE_2000DPS, ICM20648_GYRO_FULLSCALE_250DPS, ICM20648_GYRO_FULLSCALE_500DPS, ICM20648_MASK_GYRO_FULLSCALE, ICM20648_OK, ICM20648_REG_GYRO_CONFIG_1, and ICM20648_registerRead().

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_gyroCalibrate(), and ICM20648_gyroDataRead().

float ICM20648_gyroSampleRateSet ( float  sampleRate)

Sets the sample rate of the accelerometer.

Parameters
[in]sampleRateThe desired sample rate in Hz
Returns
The actual sample rate. May be different from the desired value because of the finite and discrete number of divider settings

Definition at line 380 of file icm20648.c.

References ICM20648_REG_GYRO_SMPLRT_DIV, and ICM20648_registerWrite().

Referenced by ICM20648_sampleRateSet(), and IMU_config().

uint32_t ICM20648_init ( void  )

Initializes the ICM20648 sensor. Enables the power supply and SPI lines, sets up the host SPI controller, configures the chip control interface, clock generator and interrupt line.

DO_NOT_INCLUDE_WITH_DOXYGEN

Returns
Returns zero on OK, non-zero otherwise

Definition at line 53 of file icm20648.c.

References BOARD_imuEnable(), ICM20648_BIT_CLK_PLL, ICM20648_BIT_I2C_IF_DIS, ICM20648_BIT_INT_ACTL, ICM20648_BIT_INT_OPEN, ICM20648_DEVICE_ID, ICM20648_ERROR_INVALID_DEVICE_ID, ICM20648_OK, ICM20648_REG_INT_PIN_CFG, ICM20648_REG_PWR_MGMT_1, ICM20648_REG_USER_CTRL, ICM20648_REG_WHO_AM_I, ICM20648_registerRead(), ICM20648_registerWrite(), ICM20648_reset(), ICM20648_spiInit(), and UTIL_delay().

Referenced by IMU_init().

uint32_t ICM20648_interruptEnable ( bool  dataReadyEnable,
bool  womEnable 
)

Enables or disables the interrupts in the ICM20648 chip.

Parameters
[in]dataReadyEnableIf true enables the Raw Data Ready interrupt, otherwise disables.
[in]womEnableIf true enables the Wake-up On Motion interrupt, otherwise disables.
Returns
Returns zero on OK, non-zero otherwise

Definition at line 697 of file icm20648.c.

References ICM20648_BIT_RAW_DATA_0_RDY_EN, ICM20648_BIT_WOM_INT_EN, ICM20648_OK, ICM20648_REG_INT_ENABLE, ICM20648_REG_INT_ENABLE_1, and ICM20648_registerWrite().

Referenced by ICM20648_wakeOnMotionITEnable(), IMU_config(), and IMU_gyroCalibrate().

uint32_t ICM20648_interruptStatusRead ( uint32_t *  intStatus)

Reads the interrupt status registers of the ICM20648 chip.

Parameters
[out]intStatusThe content the four interrupt registers. LSByte is INT_STATUS, MSByte is INT_STATUS_3
Returns
Returns zero on OK, non-zero otherwise

Definition at line 737 of file icm20648.c.

References ICM20648_OK, ICM20648_REG_INT_STATUS, and ICM20648_registerRead().

Referenced by IMU_config().

bool ICM20648_isDataReady ( void  )

Checks if new data is available for read.

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

Definition at line 759 of file icm20648.c.

References ICM20648_BIT_RAW_DATA_0_RDY_INT, ICM20648_REG_INT_STATUS_1, and ICM20648_registerRead().

Referenced by IMU_isDataReady().

uint32_t ICM20648_lowPowerModeEnter ( bool  enAccel,
bool  enGyro,
bool  enTemp 
)

Enables or disables the sensors in low power mode in the ICM20648 chip.

Parameters
[in]enAccelIf true enables the acceleration sensor in low power mode
[in]enGyroIf true enables the gyroscope sensor in low power mode
[in]enTempIf true enables the temperature sensor in low power mode
Returns
Returns zero on OK, non-zero otherwise

Definition at line 641 of file icm20648.c.

References ICM20648_BIT_LP_EN, ICM20648_cycleModeEnable(), ICM20648_OK, ICM20648_REG_PWR_MGMT_1, ICM20648_registerRead(), ICM20648_registerWrite(), ICM20648_sensorEnable(), ICM20648_sleepModeEnable(), and UTIL_delay().

Referenced by ICM20648_wakeOnMotionITEnable(), and IMU_config().

void ICM20648_registerRead ( uint16_t  addr,
int  numBytes,
uint8_t *  data 
)

Reads register from the ICM20648 device.

Parameters
[in]addrThe register address to read from in the sensor Bit[8:7] - bank address Bit[6:0] - register address
[in]numBytesThe number of bytes to read
[out]dataThe data read from the register
Returns
None

Definition at line 1323 of file icm20648.c.

References ICM20648_bankSelect(), USART_Rx(), and USART_Tx().

Referenced by ICM20648_accelBandwidthSet(), ICM20648_accelDataRead(), ICM20648_accelFullscaleSet(), ICM20648_accelGyroCalibrate(), ICM20648_accelResolutionGet(), ICM20648_getDeviceID(), ICM20648_gyroBandwidthSet(), ICM20648_gyroCalibrate(), ICM20648_gyroDataRead(), ICM20648_gyroFullscaleSet(), ICM20648_gyroResolutionGet(), ICM20648_init(), ICM20648_interruptStatusRead(), ICM20648_isDataReady(), ICM20648_lowPowerModeEnter(), ICM20648_sensorEnable(), ICM20648_sleepModeEnable(), and ICM20648_temperatureRead().

void ICM20648_registerWrite ( uint16_t  addr,
uint8_t  data 
)
uint32_t ICM20648_reset ( void  )

Performs soft reset on the ICM20648 chip.

Returns
Returns zero on OK, non-zero otherwise

Definition at line 120 of file icm20648.c.

References ICM20648_BIT_H_RESET, ICM20648_OK, ICM20648_REG_PWR_MGMT_1, ICM20648_registerWrite(), and UTIL_delay().

Referenced by ICM20648_init().

uint32_t ICM20648_sampleRateSet ( float  sampleRate)

Sets the sample rate both of the accelerometer and the gyroscope.

Parameters
[in]sampleRateThe desired sample rate in Hz. Since the resolution of the sample rate divider is different in the accel and gyro stages it is possible that the two sensor will have different sample rate set.
Returns
Returns zero on OK, non-zero otherwise

Definition at line 359 of file icm20648.c.

References ICM20648_accelSampleRateSet(), ICM20648_gyroSampleRateSet(), and ICM20648_OK.

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_gyroCalibrate(), and ICM20648_wakeOnMotionITEnable().

uint32_t ICM20648_sensorEnable ( bool  accel,
bool  gyro,
bool  temp 
)

Enables or disables the sensors in the ICM20648 chip.

Parameters
[in]accelIf true enables the acceleration sensor
[in]gyroIf true enables the gyroscope sensor
[in]tempIf true enables the temperature sensor
Returns
Returns zero on OK, non-zero otherwise

Definition at line 584 of file icm20648.c.

References ICM20648_BIT_PWR_ACCEL_STBY, ICM20648_BIT_PWR_GYRO_STBY, ICM20648_BIT_TEMP_DIS, ICM20648_OK, ICM20648_REG_PWR_MGMT_1, ICM20648_REG_PWR_MGMT_2, ICM20648_registerRead(), and ICM20648_registerWrite().

Referenced by ICM20648_accelGyroCalibrate(), ICM20648_gyroCalibrate(), ICM20648_lowPowerModeEnter(), ICM20648_wakeOnMotionITEnable(), and IMU_config().

uint32_t ICM20648_sleepModeEnable ( bool  enable)

Enables or disables the sleep mode of the device.

Parameters
[in]enableIf true, sleep mode is enabled. Set to false to disable sleep mode.
Returns
Returns zero on OK, non-zero otherwise

Definition at line 518 of file icm20648.c.

References ICM20648_BIT_SLEEP, ICM20648_OK, ICM20648_REG_PWR_MGMT_1, ICM20648_registerRead(), and ICM20648_registerWrite().

Referenced by ICM20648_lowPowerModeEnter(), and ICM20648_wakeOnMotionITEnable().

uint32_t ICM20648_spiInit ( void  )

Initializes the SPI bus in order to communicate with the ICM20648.

Returns
Returns zero on OK, non-zero otherwise

Definition at line 1272 of file icm20648.c.

References CMU_ClockEnable(), cmuClock_GPIO, cmuClock_HFPER, GPIO_PinModeSet(), gpioModeInput, gpioModePushPull, ICM20648_OK, USART_InitSync(), and USART_Reset().

Referenced by ICM20648_init().

uint32_t ICM20648_temperatureRead ( float *  temperature)

Reads the temperature sensor raw value and converts to Celsius.

Parameters
[out]temperatureThe mesured temperature in Celsius
Returns
Returns zero on OK, non-zero otherwise

Definition at line 1227 of file icm20648.c.

References ICM20648_OK, ICM20648_REG_TEMPERATURE_H, and ICM20648_registerRead().

uint32_t ICM20648_wakeOnMotionITEnable ( bool  enable,
uint8_t  womThreshold,
float  sampleRate 
)

Sets up and enables the Wake-up On Motion feature.

Parameters
[in]enableIf true enables the WOM feature, disables otherwise
[in]womThresholdThreshold value for the Wake on Motion Interrupt for ACCEL x/y/z axes. LSB = 4mg. Range is 0mg to 1020mg
[in]sampleRateThe desired sample rate of the accel sensor in Hz
Returns
Returns zero on OK, non-zero otherwise

Definition at line 793 of file icm20648.c.

References ICM20648_ACCEL_BW_1210HZ, ICM20648_ACCEL_FULLSCALE_2G, ICM20648_accelBandwidthSet(), ICM20648_accelFullscaleSet(), ICM20648_BIT_ACCEL_INTEL_EN, ICM20648_BIT_ACCEL_INTEL_MODE, ICM20648_cycleModeEnable(), ICM20648_interruptEnable(), ICM20648_lowPowerModeEnter(), ICM20648_OK, ICM20648_REG_ACCEL_INTEL_CTRL, ICM20648_REG_ACCEL_WOM_THR, ICM20648_registerWrite(), ICM20648_sampleRateSet(), ICM20648_sensorEnable(), ICM20648_sleepModeEnable(), and UTIL_delay().