Go to the documentation of this file.
42 #ifdef PREINIT_SUPPORTED
46 #ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
66 #define MPU9DOF_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.fsy = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77 #define MPU9DOF_RETVAL uint8_t
79 #define MPU9DOF_OK 0x00
80 #define MPU9DOF_INIT_ERROR 0xFF
87 #define MPU9DOF_XLG_I2C_ADDR_1 0x69 //Device address jumper pos 1 (0xD2 >> 1)
88 #define MPU9DOF_XLG_I2C_ADDR_0 0x68 //Device address jumper pos 0
89 #define MPU9DOF_M_I2C_ADDR_0 0x0C // Address of the magnetometer in bypass mode
90 #define MPU9DOF_M_I2C_ADDR_1 0x0D
97 #define MPU9DOF_WHO_AM_I_MAG 0x00 // should return = 0x48
98 #define MPU9DOF_INFO 0x01
99 #define MPU9DOF_MAG_ST1 0x02 // data ready status bit 0
100 #define MPU9DOF_MAG_ADDRESS 0x0C
101 #define MPU9DOF_MAG_XOUT_L 0x03 // data
102 #define MPU9DOF_MAG_XOUT_H 0x04
103 #define MPU9DOF_MAG_YOUT_L 0x05
104 #define MPU9DOF_MAG_YOUT_H 0x06
105 #define MPU9DOF_MAG_ZOUT_L 0x07
106 #define MPU9DOF_MAG_ZOUT_H 0x08
107 #define MPU9DOF_MAG_ST2 0x09 // Data overflow bit 3 and data read error status bit 2
108 #define MPU9DOF_MAG_CNTL 0x0A // Power down (0000), single-measurement (0001), self-test (1000) and Fuse ROM (1111) modes on bits 3:0
109 #define MPU9DOF_MAG_ASTC 0x0C // Self test control
110 #define MPU9DOF_MAG_ASAX 0x10 // Fuse ROM x-axis sensitivity adjustment value
111 #define MPU9DOF_MAG_ASAY 0x11 // Fuse ROM y-axis sensitivity adjustment value
112 #define MPU9DOF_MAG_ASAZ 0x12 // Fuse ROM z-axis sensitivity adjustment value
114 #define MPU9DOF_XGOFFS_TC 0x00 // Bit 7 PWR_MODE, bits 6:1 XG_OFFS_TC, bit 0 OTP_BNK_VLD
115 #define MPU9DOF_YGOFFS_TC 0x01
116 #define MPU9DOF_ZGOFFS_TC 0x02
117 #define MPU9DOF_X_FINE_GAIN 0x03 // [7:0] fine gain
118 #define MPU9DOF_Y_FINE_GAIN 0x04
119 #define MPU9DOF_Z_FINE_GAIN 0x05
120 #define MPU9DOF_XA_OFFSET_H 0x06 // User-defined trim values for accelerometer
121 #define MPU9DOF_XA_OFFSET_L_TC 0x07
122 #define MPU9DOF_YA_OFFSET_H 0x08
123 #define MPU9DOF_YA_OFFSET_L_TC 0x09
124 #define MPU9DOF_ZA_OFFSET_H 0x0A
125 #define MPU9DOF_ZA_OFFSET_L_TC 0x0B
126 #define MPU9DOF_SELF_TEST_X 0x0D
127 #define MPU9DOF_SELF_TEST_Y 0x0E
128 #define MPU9DOF_SELF_TEST_Z 0x0F
129 #define MPU9DOF_SELF_TEST_A 0x10
130 #define MPU9DOF_XG_OFFS_USRH 0x13 // User-defined trim values for gyroscope, populate with calibration routine
131 #define MPU9DOF_XG_OFFS_USRL 0x14
132 #define MPU9DOF_YG_OFFS_USRH 0x15
133 #define MPU9DOF_YG_OFFS_USRL 0x16
134 #define MPU9DOF_ZG_OFFS_USRH 0x17
135 #define MPU9DOF_ZG_OFFS_USRL 0x18
136 #define MPU9DOF_SMPLRT_DIV 0x19
137 #define MPU9DOF_CONFIG 0x1A
138 #define MPU9DOF_GYRO_CONFIG 0x1B
139 #define MPU9DOF_ACCEL_CONFIG 0x1C
140 #define MPU9DOF_FF_THR 0x1D // Free-fall
141 #define MPU9DOF_FF_DUR 0x1E // Free-fall
142 #define MPU9DOF_MOT_THR 0x1F // Motion detection threshold bits [7:0]
143 #define MPU9DOF_MOT_DUR 0x20 // Duration counter threshold for motion interrupt generation, 1 kHz rate, LSB = 1 ms
144 #define MPU9DOF_ZMOT_THR 0x21 // Zero-motion detection threshold bits [7:0]
145 #define MPU9DOF_ZRMOT_DUR 0x22 // Duration counter threshold for zero motion interrupt generation, 16 Hz rate, LSB = 64 ms
146 #define MPU9DOF_FIFO_EN 0x23
147 #define MPU9DOF_I2C_MST_CTRL 0x24
148 #define MPU9DOF_I2C_SLV0_ADDR 0x25
149 #define MPU9DOF_I2C_SLV0_REG 0x26
150 #define MPU9DOF_I2C_SLV0_CTRL 0x27
151 #define MPU9DOF_I2C_SLV1_ADDR 0x28
152 #define MPU9DOF_I2C_SLV1_REG 0x29
153 #define MPU9DOF_I2C_SLV1_CTRL 0x2A
154 #define MPU9DOF_I2C_SLV2_ADDR 0x2B
155 #define MPU9DOF_I2C_SLV2_REG 0x2C
156 #define MPU9DOF_I2C_SLV2_CTRL 0x2D
157 #define MPU9DOF_I2C_SLV3_ADDR 0x2E
158 #define MPU9DOF_I2C_SLV3_REG 0x2F
159 #define MPU9DOF_I2C_SLV3_CTRL 0x30
160 #define MPU9DOF_I2C_SLV4_ADDR 0x31
161 #define MPU9DOF_I2C_SLV4_REG 0x32
162 #define MPU9DOF_I2C_SLV4_DO 0x33
163 #define MPU9DOF_I2C_SLV4_CTRL 0x34
164 #define MPU9DOF_I2C_SLV4_DI 0x35
165 #define MPU9DOF_I2C_MST_STATUS 0x36
166 #define MPU9DOF_INT_PIN_CFG 0x37
167 #define MPU9DOF_INT_ENABLE 0x38
168 #define MPU9DOF_DMP_INT_STATUS 0x39 // Check DMP interrupt
169 #define MPU9DOF_INT_STATUS 0x3A
170 #define MPU9DOF_ACCEL_XOUT_H 0x3B
171 #define MPU9DOF_ACCEL_XOUT_L 0x3C
172 #define MPU9DOF_ACCEL_YOUT_H 0x3D
173 #define MPU9DOF_ACCEL_YOUT_L 0x3E
174 #define MPU9DOF_ACCEL_ZOUT_H 0x3F
175 #define MPU9DOF_ACCEL_ZOUT_L 0x40
176 #define MPU9DOF_TEMP_OUT_H 0x41
177 #define MPU9DOF_TEMP_OUT_L 0x42
178 #define MPU9DOF_GYRO_XOUT_H 0x43
179 #define MPU9DOF_GYRO_XOUT_L 0x44
180 #define MPU9DOF_GYRO_YOUT_H 0x45
181 #define MPU9DOF_GYRO_YOUT_L 0x46
182 #define MPU9DOF_GYRO_ZOUT_H 0x47
183 #define MPU9DOF_GYRO_ZOUT_L 0x48
184 #define MPU9DOF_EXT_SENS_DATA_00 0x49
185 #define MPU9DOF_EXT_SENS_DATA_01 0x4A
186 #define MPU9DOF_EXT_SENS_DATA_02 0x4B
187 #define MPU9DOF_EXT_SENS_DATA_03 0x4C
188 #define MPU9DOF_EXT_SENS_DATA_04 0x4D
189 #define MPU9DOF_EXT_SENS_DATA_05 0x4E
190 #define MPU9DOF_EXT_SENS_DATA_06 0x4F
191 #define MPU9DOF_EXT_SENS_DATA_07 0x50
192 #define MPU9DOF_EXT_SENS_DATA_08 0x51
193 #define MPU9DOF_EXT_SENS_DATA_09 0x52
194 #define MPU9DOF_EXT_SENS_DATA_10 0x53
195 #define MPU9DOF_EXT_SENS_DATA_11 0x54
196 #define MPU9DOF_EXT_SENS_DATA_12 0x55
197 #define MPU9DOF_EXT_SENS_DATA_13 0x56
198 #define MPU9DOF_EXT_SENS_DATA_14 0x57
199 #define MPU9DOF_EXT_SENS_DATA_15 0x58
200 #define MPU9DOF_EXT_SENS_DATA_16 0x59
201 #define MPU9DOF_EXT_SENS_DATA_17 0x5A
202 #define MPU9DOF_EXT_SENS_DATA_18 0x5B
203 #define MPU9DOF_EXT_SENS_DATA_19 0x5C
204 #define MPU9DOF_EXT_SENS_DATA_20 0x5D
205 #define MPU9DOF_EXT_SENS_DATA_21 0x5E
206 #define MPU9DOF_EXT_SENS_DATA_22 0x5F
207 #define MPU9DOF_EXT_SENS_DATA_23 0x60
208 #define MPU9DOF_MOT_DETECT_STATUS 0x61
209 #define MPU9DOF_I2C_SLV0_DO 0x63
210 #define MPU9DOF_I2C_SLV1_DO 0x64
211 #define MPU9DOF_I2C_SLV2_DO 0x65
212 #define MPU9DOF_I2C_SLV3_DO 0x66
213 #define MPU9DOF_I2C_MST_DELAY_CTRL 0x67
214 #define MPU9DOF_SIGNAL_PATH_RESET 0x68
215 #define MPU9DOF_MOT_DETECT_CTRL 0x69
216 #define MPU9DOF_USER_CTRL 0x6A // Bit 7 enable DMP, bit 3 reset DMP
217 #define MPU9DOF_PWR_MGMT_1 0x6B // Device defaults to the SLEEP mode
218 #define MPU9DOF_PWR_MGMT_2 0x6C
219 #define MPU9DOF_DMP_BANK 0x6D // Activates a specific bank in the DMP
220 #define MPU9DOF_DMP_RW_PNT 0x6E // Set read/write pointer to a specific start address in specified DMP bank
221 #define MPU9DOF_DMP_REG 0x6F // Register in DMP from which to read or to which to write
222 #define MPU9DOF_DMP_REG_1 0x70
223 #define MPU9DOF_DMP_REG_2 0x71
224 #define MPU9DOF_FIFO_COUNTH 0x72
225 #define MPU9DOF_FIFO_COUNTL 0x73
226 #define MPU9DOF_FIFO_R_W 0x74
227 #define MPU9DOF_WHO_AM_I_XLG 0x75 // Should return = 0x68
234 #define MPU9DOF_BIT_SLEEP 0x40
235 #define MPU9DOF_BIT_H_RESET 0x80
236 #define MPU9DOF_BITS_CLKSEL 0x07
237 #define MPU9DOF_MPU_CLK_SEL_PLLGYROX 0x01
238 #define MPU9DOF_MPU_CLK_SEL_PLLGYROZ 0x03
239 #define MPU9DOF_MPU_EXT_SYNC_GYROX 0x02
240 #define MPU9DOF_BITS_AFSL_SEL_2G 0x00
241 #define MPU9DOF_BITS_AFSL_SEL_4G 0x08
242 #define MPU9DOF_BITS_AFSL_SEL_8G 0x10
243 #define MPU9DOF_BITS_AFSL_SEL_16G 0x18
244 #define MPU9DOF_BITS_FS_250DPS 0x00
245 #define MPU9DOF_BITS_FS_500DPS 0x08
246 #define MPU9DOF_BITS_FS_1000DPS 0x10
247 #define MPU9DOF_BITS_FS_2000DPS 0x18
248 #define MPU9DOF_BITS_FS_MASK 0x18
249 #define MPU9DOF_BITS_DLPF_CFG_256HZ_NOLPF2 0x00
250 #define MPU9DOF_BITS_DLPF_CFG_188HZ 0x01
251 #define MPU9DOF_BITS_DLPF_CFG_98HZ 0x02
252 #define MPU9DOF_BITS_DLPF_CFG_42HZ 0x03
253 #define MPU9DOF_BITS_DLPF_CFG_20HZ 0x04
254 #define MPU9DOF_BITS_DLPF_CFG_10HZ 0x05
255 #define MPU9DOF_BITS_DLPF_CFG_5HZ 0x06
256 #define MPU9DOF_BITS_DLPF_CFG_2100HZ_NOLPF 0x07
257 #define MPU9DOF_BITS_DLPF_CFG_MASK 0x07
258 #define MPU9DOF_BIT_INT_ANYRD_2CLEAR 0x10
259 #define MPU9DOF_BIT_RAW_RDY_EN 0x01
260 #define MPU9DOF_BIT_I2C_IF_DIS 0x10
261 #define MPU9DOF_BIT_INT_PIN_CFG 0x02
262 #define MPU9DOF_BIT_FIFO_EN 0x78
263 #define MPU9DOF_BIT_FIFO_DIS 0x00
264 #define MPU9DOF_DEFAULT 0x00
512 #endif // _MPU9DOF_H_
uint8_t slave_address
Definition: mpu9dof.h:293
void mpu9dof_cfg_setup(mpu9dof_cfg_t *cfg)
Config Object Initialization function.
pin_name_t int_pin
Definition: mpu9dof.h:311
void mpu9dof_generic_read(mpu9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t sda
Definition: mpu9dof.h:306
int16_t mpu9dof_get_axis_mag(mpu9dof_t *ctx, uint8_t adr_reg_low)
Function get low and high register data.
void mpu9dof_write_data_mag(mpu9dof_t *ctx, uint8_t address, uint8_t write_command)
Generic write data function.
Click configuration structure definition.
Definition: mpu9dof.h:302
pin_name_t scl
Definition: mpu9dof.h:305
void adapter_turn_fsy_on(mpu9dof_t *ctx)
Turn FSY on function.
pin_name_t fsy
Definition: mpu9dof.h:310
void mpu9dof_default_cfg(mpu9dof_t *ctx)
Click Default Configuration function.
uint8_t get_int_pin_state(mpu9dof_t *ctx)
Get int pin state.
void mpu9dof_generic_write(mpu9dof_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
float mpu9dof_read_temperature(mpu9dof_t *ctx)
Function read temperature data in degrees [ �C ].
void mpu9dof_read_accel(mpu9dof_t *ctx, int16_t *accel_x, int16_t *accel_y, int16_t *accel_z)
Function read axis.
i2c_master_t i2c
Definition: mpu9dof.h:289
void adapter_turn_fsy_off(mpu9dof_t *ctx)
Turn FSY off function.
uint8_t i2c_mag_address
Definition: mpu9dof.h:317
int16_t mpu9dof_get_axis(mpu9dof_t *ctx, uint8_t adr_reg_high)
Function get low and high register data.
void mpu9dof_read_mag(mpu9dof_t *ctx, int16_t *mag_x, int16_t *mag_y, int16_t *mag_z)
Function read axis.
digital_in_t int_pin
Definition: mpu9dof.h:285
void mpu9dof_read_gyro(mpu9dof_t *ctx, int16_t *gyro_x, int16_t *gyro_y, int16_t *gyro_z)
Function read axis.
uint8_t mpu9dof_read_data_mag(mpu9dof_t *ctx, uint8_t address)
Generic read data function.
uint8_t i2c_address
Definition: mpu9dof.h:316
uint8_t magnetometer_address
Definition: mpu9dof.h:294
uint32_t i2c_speed
Definition: mpu9dof.h:315
#define MPU9DOF_RETVAL
Definition: mpu9dof.h:77
digital_out_t fsy
Definition: mpu9dof.h:281
Click ctx object definition.
Definition: mpu9dof.h:278
MPU9DOF_RETVAL mpu9dof_init(mpu9dof_t *ctx, mpu9dof_cfg_t *cfg)
Initialization function.