Master Thesis  V1.0
Research and Design of Sensor Node for NMSD Treatment
ICM20948.h
Go to the documentation of this file.
1 /***************************************************************************/
10 /*
11  * ICM20948.h
12  *
13  * Created on: Nov 12, 2019
14  * Author: jonac
15  */
16 
17 #ifndef ICM_20948_ICM20948_H_
18 #define ICM_20948_ICM20948_H_
19 
20 #include <stdint.h>
21 #include <stdbool.h>
22 /*********************************/
23 
24 /*********************************/
25 
26 void ICM_20948_power (bool enable);
27 
28 void ICM_20948_Init ();
29 void ICM_20948_Init2();
30 void ICM_20948_Init_SPI ();
31 void ICM_20948_enable_SPI(bool enable);
32 
33 void ICM_20948_chipSelectSet ( bool enable );
34 void ICM_20948_bankSelect ( uint8_t bank );
35 
36 uint8_t ICM_20948_read ( uint16_t addr );
37 void ICM_20948_registerRead(uint16_t addr, int numBytes, uint8_t *data);
38 
39 
41 
42 void ICM_20948_write ( uint16_t addr, uint8_t data );
43 
44 uint32_t ICM_20948_sleepModeEnable ( bool enable );
45 uint32_t ICM_20948_reset(void);
46 
47 
48 uint32_t ICM_20948_gyroDataRead(float *gyro);
49 uint32_t ICM_20948_gyroResolutionGet(float *gyroRes);
50 uint32_t ICM_20948_gyroFullscaleSet(uint8_t gyroFs);
51 uint32_t ICM_20948_gyroBandwidthSet(uint8_t gyroBw);
52 float ICM_20948_gyroSampleRateSet(float sampleRate);
53 
54 uint32_t ICM_20948_accelDataRead(float *accel);
55 uint32_t ICM_20948_accelResolutionGet(float *accelRes);
56 uint32_t ICM_20948_accelFullscaleSet(uint8_t accelFs);
57 uint32_t ICM_20948_accelBandwidthSet(uint8_t accelBw);
58 float ICM_20948_accelSampleRateSet(float sampleRate);
59 
60 
61 uint32_t ICM_20948_interruptEnable(bool dataReadyEnable, bool womEnable);
62 uint32_t ICM_20948_interruptStatusRead(uint32_t *intStatus);
63 uint32_t ICM_20948_wakeOnMotionITEnable(bool enable, uint8_t womThreshold, float sampleRate);
64 uint32_t ICM_20948_latchEnable(bool enable);
65 
66 
67 uint32_t ICM_20948_sampleRateSet(float sampleRate);
68 
69 uint32_t ICM_20948_lowPowerModeEnter(bool enAccel, bool enGyro, bool enTemp);
70 uint32_t ICM_20948_sensorEnable(bool accel, bool gyro, bool temp);
71 uint32_t ICM_20948_cycleModeEnable(bool enable);
72 
73 /* Magnetometer functions */
74 void ICM_20948_set_mag_transfer(bool read);
75 void ICM_20948_read_mag_register(uint8_t addr, uint8_t numBytes, uint8_t *data);
76 void ICM_20948_write_mag_register(uint8_t addr, uint8_t data);
77 uint32_t ICM_20948_set_mag_mode(uint8_t magMode);
78 void ICM_20948_magRawDataRead(float *raw_magn);
79 void ICM_20948_magDataRead(float *magn);
80 uint32_t ICM_20948_reset_mag(void);
81 
82 void ICM_20948_registerWrite(uint16_t addr, uint8_t data);
83 
84 /* Embedded 2 test */
85 void ICM_20948_magn_to_angle(float *magn, float *angle);
86 
90 uint32_t ICM_20948_accelGyroCalibrate(float *accelBiasScaled, float *gyroBiasScaled);
91 uint32_t ICM_20948_gyroCalibrate( float *gyroBiasScaled );
92 uint32_t ICM_20948_min_max_mag( int16_t *minMag, int16_t *maxMag );
93 bool ICM_20948_calibrate_mag( float *offset, float *scale );
94 
95 
96 
97 #endif /* ICM_20948_ICM20948_H_ */
ICM_20948_gyroCalibrate
uint32_t ICM_20948_gyroCalibrate(float *gyroBiasScaled)
Gyroscope calibration function. Reads the gyroscope values while the device is at rest and in level....
Definition: ICM20948.c:2031
ICM_20948_chipSelectSet
void ICM_20948_chipSelectSet(bool enable)
Set chipselect pin for SPI functionality.
Definition: ICM20948.c:480
data
MeasurementData_t data
Definition: main.c:122
ICM_20948_set_mag_transfer
void ICM_20948_set_mag_transfer(bool read)
Set magnetometer data transfer on integrated I2C controller inside ICM20948.
Definition: ICM20948.c:1443
ICM_20948_sensorEnable
uint32_t ICM_20948_sensorEnable(bool accel, bool gyro, bool temp)
Enable selected sensors.
Definition: ICM20948.c:1095
ICM_20948_accelSampleRateSet
float ICM_20948_accelSampleRateSet(float sampleRate)
Sets the accelerometer sample rate.
Definition: ICM20948.c:988
ICM_20948_read_mag_register
void ICM_20948_read_mag_register(uint8_t addr, uint8_t numBytes, uint8_t *data)
Read register in the AK09916 magnetometer device.
Definition: ICM20948.c:1594
ICM_20948_enable_SPI
void ICM_20948_enable_SPI(bool enable)
Enables the necessary SPI interface to communicate with ICM20948.
Definition: ICM20948.c:344
ICM_20948_wakeOnMotionITEnable
uint32_t ICM_20948_wakeOnMotionITEnable(bool enable, uint8_t womThreshold, float sampleRate)
Set wake on motion interrupt.
Definition: ICM20948.c:1295
ICM_20948_Init
void ICM_20948_Init()
Init function for ICM20948.
Definition: ICM20948.c:85
ICM_20948_write_mag_register
void ICM_20948_write_mag_register(uint8_t addr, uint8_t data)
Writes a uint8_t to the I2C address of the magnetometer of the ICM_20948.
Definition: ICM20948.c:1648
ICM_20948_Init2
void ICM_20948_Init2()
Second init function for ICM20948, use when waking from sleep.
Definition: ICM20948.c:169
ICM_20948_reset_mag
uint32_t ICM_20948_reset_mag(void)
Reset magnetometer.
Definition: ICM20948.c:1768
ICM_20948_set_mag_mode
uint32_t ICM_20948_set_mag_mode(uint8_t magMode)
Set magnetometer mode (sample rate / on-off)
Definition: ICM20948.c:1670
ICM_20948_accelDataRead
uint32_t ICM_20948_accelDataRead(float *accel)
Read RAW accelerometer data.
Definition: ICM20948.c:1170
ICM_20948_magn_to_angle
void ICM_20948_magn_to_angle(float *magn, float *angle)
Test function for non-tilt compensated compass.
Definition: ICM20948.c:1793
ICM_20948_gyroResolutionGet
uint32_t ICM_20948_gyroResolutionGet(float *gyroRes)
Set gyro resolution.
Definition: ICM20948.c:817
ICM_20948_registerRead
void ICM_20948_registerRead(uint16_t addr, int numBytes, uint8_t *data)
Read registers from IMU.
Definition: ICM20948.c:654
ICM_20948_min_max_mag
uint32_t ICM_20948_min_max_mag(int16_t *minMag, int16_t *maxMag)
Calculate minimum and maximum magnetometer values, which are used for calibration.
Definition: ICM20948.c:2186
ICM_20948_gyroDataRead
uint32_t ICM_20948_gyroDataRead(float *gyro)
Read gyroscope data from IMU.
Definition: ICM20948.c:783
ICM_20948_reset
uint32_t ICM_20948_reset(void)
Reset IMU.
Definition: ICM20948.c:762
ICM_20948_write
void ICM_20948_write(uint16_t addr, uint8_t data)
ICM_20948_accelBandwidthSet
uint32_t ICM_20948_accelBandwidthSet(uint8_t accelBw)
Set acceleromter bandwidth.
Definition: ICM20948.c:1376
ICM_20948_read
uint8_t ICM_20948_read(uint16_t addr)
Read single register from IMU using SPI.
Definition: ICM20948.c:545
ICM_20948_gyroSampleRateSet
float ICM_20948_gyroSampleRateSet(float sampleRate)
Sets the gyro sample rate.
Definition: ICM20948.c:947
ICM_20948_sampleRateSet
uint32_t ICM_20948_sampleRateSet(float sampleRate)
Combination function to set sample rate of gyro and accel at once.
Definition: ICM20948.c:924
ICM_20948_calibrate_mag
bool ICM_20948_calibrate_mag(float *offset, float *scale)
Magnetometer calibration function. Get magnetometer minimum and maximum values, while moving the devi...
Definition: ICM20948.c:2289
ICM_20948_interruptStatusRead
uint32_t ICM_20948_interruptStatusRead(uint32_t *intStatus)
Read staus of interrupt IMU.
Definition: ICM20948.c:857
ICM_20948_cycleModeEnable
uint32_t ICM_20948_cycleModeEnable(bool enable)
Enable cycle mode on IMU.
Definition: ICM20948.c:1142
ICM_20948_registerWrite
void ICM_20948_registerWrite(uint16_t addr, uint8_t data)
Writes registers from IMU.
Definition: ICM20948.c:697
ICM_20948_lowPowerModeEnter
uint32_t ICM_20948_lowPowerModeEnter(bool enAccel, bool enGyro, bool enTemp)
Enter low power mode for selected sensors.
Definition: ICM20948.c:1037
ICM_20948_accelGyroCalibrate
uint32_t ICM_20948_accelGyroCalibrate(float *accelBiasScaled, float *gyroBiasScaled)
Accelerometer and gyroscope calibration function. Reads the gyroscope and accelerometer values while ...
Definition: ICM20948.c:1820
ICM_20948_accelFullscaleSet
uint32_t ICM_20948_accelFullscaleSet(uint8_t accelFs)
Set accelerometer full scale range.
Definition: ICM20948.c:1242
ICM_20948_interruptEnable
uint32_t ICM_20948_interruptEnable(bool dataReadyEnable, bool womEnable)
Enable interrupt for data ready or wake on motion.
Definition: ICM20948.c:885
ICM_20948_bankSelect
void ICM_20948_bankSelect(uint8_t bank)
Select appropriate bank in ICM20948 based on first bits of address.
Definition: ICM20948.c:528
ICM_20948_gyroBandwidthSet
uint32_t ICM_20948_gyroBandwidthSet(uint8_t gyroBw)
Set gyroscope bandwidth.
Definition: ICM20948.c:1352
ICM_20948_magRawDataRead
void ICM_20948_magRawDataRead(float *raw_magn)
Read magnetometer raw values.
Definition: ICM20948.c:1707
ICM_20948_Init_SPI
void ICM_20948_Init_SPI()
Initiate SPI functionality for ICM20948.
Definition: ICM20948.c:273
ICM_20948_magDataRead
void ICM_20948_magDataRead(float *magn)
Convert raw magnetometer values to calibrated and scaled ones.
Definition: ICM20948.c:1745
ICM_20948_accelResolutionGet
uint32_t ICM_20948_accelResolutionGet(float *accelRes)
Get accelerometer resultion.
Definition: ICM20948.c:1202
ICM_20948_latchEnable
uint32_t ICM_20948_latchEnable(bool enable)
Enables / disables the 50 micro seconds interrupt pin functionality.
Definition: ICM20948.c:1403
ICM_20948_sleepModeEnable
uint32_t ICM_20948_sleepModeEnable(bool enable)
Sleep mode enable function.
Definition: ICM20948.c:728
ICM_20948_power
void ICM_20948_power(bool enable)
Turns the GPIO pin high to provide power to the ICM20948.
Definition: ICM20948.c:392
ICM_20948_printAllData
void ICM_20948_printAllData()
Print all gyro + accel + magn data using dbprint.
Definition: ICM20948.c:414
ICM_20948_gyroFullscaleSet
uint32_t ICM_20948_gyroFullscaleSet(uint8_t gyroFs)
Set gyroscope full scale range.
Definition: ICM20948.c:1265