40 #define MPU_ADDRESS (0x68) 42 #define GYRO_INT_PIN (Pin_13) 44 #define MPU_RA_WHO_AM_I (0x75) 45 #define MPU_RA_GYRO_XOUT_H (0x43) 46 #define MPU_RA_ACCEL_XOUT_H (0x3B) 47 #define MPU_RA_TEMP_OUT_A (0x41) 49 #define MPU_RA_XA_OFFS_H (0x06) //[15:0] XA_OFFS 50 #define MPU_RA_PRODUCT_ID (0x0C) // Product ID Register 53 #define MPUx0x0_WHO_AM_I_CONST (0x68) 98 #define MPU_RA_SMPLRT_DIV 0x19 99 #define MPU_RA_CONFIG 0x1A 100 #define MPU_RA_GYRO_CONFIG 0x1B 101 #define MPU_RA_ACCEL_CONFIG 0x1C 102 #define MPU_RA_FIFO_EN 0x23 103 #define MPU_RA_I2C_MST_CTRL 0x24 104 #define MPU_RA_INT_PIN_CFG 0x37 105 #define MPU_RA_INT_ENABLE 0x38 106 #define MPU_RA_SIGNAL_PATH_RST 0x68 107 #define MPU_RA_USER_CTRL 0x6A 108 #define MPU_RA_PWR_MGMT_1 0x6B 109 #define MPU_RA_PWR_MGMT_2 0x6C 110 #define MPU_RA_FIFO_COUNT_H 0x72 111 #define MPU_RA_FIFO_R_W 0x74 114 #define MPU6050_INV_CLK_GYROZ 0x03 115 #define MPU6050_BIT_FIFO_RST 0x04 116 #define MPU6050_BIT_DMP_RST 0x08 117 #define MPU6050_BIT_FIFO_EN 0x40 143 if (boardVersion > 4) {
175 void mpu6050_init(
bool enableInterrupt, uint16_t * acc1G,
float * gyroScale,
int boardVersion)
183 *gyroScale = (1.0f / 16.4f) * (
M_PI / 180.0
f);
186 if (enableInterrupt) {
190 if (boardVersion > 4){
216 void mpu6050_read_all(int16_t *accData, int16_t *gyroData, int16_t* tempData, uint64_t *time_us)
222 accData[0] = (int16_t)((buf[0] << 8) | buf[1]);
223 accData[1] = (int16_t)((buf[2] << 8) | buf[3]);
224 accData[2] = (int16_t)((buf[4] << 8) | buf[5]);
226 (*tempData) = (int16_t)((buf[6] << 8) | buf[7]);
228 gyroData[0] = (int16_t)((buf[8] << 8) | buf[9]);
229 gyroData[1] = (int16_t)((buf[10] << 8) | buf[11]);
230 gyroData[2] = (int16_t)((buf[12] << 8) | buf[13]);
243 accData[0] = (int16_t)((buf[0] << 8) | buf[1]);
244 accData[1] = (int16_t)((buf[2] << 8) | buf[3]);
245 accData[2] = (int16_t)((buf[4] << 8) | buf[5]);
256 gyroData[0] = (int16_t)((buf[0] << 8) | buf[1]);
257 gyroData[1] = (int16_t)((buf[2] << 8) | buf[3]);
258 gyroData[2] = (int16_t)((buf[4] << 8) | buf[5]);
267 *tempData = (int16_t)((buf[0] << 8) | buf[1]) / 4;
277 static volatile int16_t
gyro[3];
316 void mpu6050_async_read_all(
volatile int16_t *accData,
volatile int16_t *tempData,
volatile int16_t *gyroData,
volatile uint64_t* timeData)
318 accData[0] =
accel[0];
319 accData[1] =
accel[1];
320 accData[2] =
accel[2];
322 gyroData[0] =
gyro[0];
323 gyroData[1] =
gyro[1];
324 gyroData[2] =
gyro[2];
FunctionalState EXTI_LineCmd
EXTITrigger_TypeDef EXTI_Trigger
#define MPU_RA_SMPLRT_DIV
void EXTI15_10_IRQHandler(void)
static volatile int16_t gyro[3]
void NVIC_Init(NVIC_InitTypeDef *NVIC_InitStruct)
Initializes the NVIC peripheral according to the specified parameters in the NVIC_InitStruct.
bool i2cRead(uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t *buf)
EXTI Init Structure definition.
uint64_t measurement_time
void mpu6050_request_async_update_all()
static uint64_t imu_time_us
#define MPU_RA_GYRO_CONFIG
#define MPU_RA_INT_PIN_CFG
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Enables or disables the High Speed APB (APB2) peripheral clock.
uint8_t NVIC_IRQChannelSubPriority
void mpu6050_async_read_all(volatile int16_t *accData, volatile int16_t *tempData, volatile int16_t *gyroData, volatile uint64_t *timeData)
NVIC Init Structure definition.
#define MPU_RA_GYRO_XOUT_H
void gpioInit(GPIO_TypeDef *gpio, gpio_config_t *config)
volatile uint64_t micros(void)
void mpu6050_init(bool enableInterrupt, uint16_t *acc1G, float *gyroScale, int boardVersion)
ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
Checks whether the specified EXTI line is asserted or not.
void mpu6050_read_all(int16_t *accData, int16_t *gyroData, int16_t *tempData, uint64_t *time_us)
void EXTI_Init(EXTI_InitTypeDef *EXTI_InitStruct)
Initializes the EXTI peripheral according to the specified parameters in the EXTI_InitStruct. EXTI_Line specifies the EXTI line (EXTI0....EXTI35). EXTI_Mode specifies which EXTI line is used as interrupt or an event. EXTI_Trigger selects the trigger. When the trigger occurs, interrupt pending bit will be set. EXTI_LineCmd controls (Enable/Disable) the EXTI line.
bool i2cWrite(uint8_t addr_, uint8_t reg_, uint8_t data)
EXTIMode_TypeDef EXTI_Mode
static volatile int16_t accel[3]
void mpu6050_read_gyro(int16_t *gyroData)
void mpu6050_read_temperature(int16_t *tempData)
#define GPIO_PortSourceGPIOB
static volatile int16_t temp
#define RCC_APB2Periph_AFIO
static volatile uint8_t reg
#define MPU6050_INV_CLK_GYROZ
static uint8_t mpuLowPassFilter
void mpu6050_exti_init(int boardVersion)
void i2c_queue_job(i2cJobType_t type, uint8_t addr_, uint8_t reg_, uint8_t *data, uint8_t length, volatile uint8_t *status_, void(*CB)(uint8_t))
FunctionalState NVIC_IRQChannelCmd
#define MPU_RA_TEMP_OUT_A
uint8_t NVIC_IRQChannelPreemptionPriority
void gpioExtiLineConfig(uint8_t portsrc, uint8_t pinsrc)
#define MPU_RA_ACCEL_XOUT_H
static bool mpuWriteRegisterI2C(uint8_t reg, uint8_t data)
#define MPU_RA_ACCEL_CONFIG
static bool mpuReadRegisterI2C(uint8_t reg, uint8_t *data, int length)
#define MPU_RA_PWR_MGMT_1
void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
Clears the EXTI's line pending bits.
#define GPIO_PortSourceGPIOC
void read_all_CB(uint8_t result)
static volatile bool need_to_queue_new_i2c_job
#define MPU_RA_INT_ENABLE
void mpu6050_read_accel(int16_t *accData)