[mw_shl_code=c,true]float yaw = 0;
void TIM2_IRQHandler(void)
{
uint8_t gyroAcc[14];
uint8_t mag[6];
if (TIM_GetITStatus(TIM2,TIM_IT_Update)!= RESET)
{
LED_Set(Bit_RESET);
MPU9250_ReadGyroAcc(gyroAcc);
temperature = (int16_t)(((uint16_t)gyroAcc[6]<<8) | gyroAcc[7]);
gyrox = (int16_t)(((uint16_t)gyroAcc[8]<<8) | gyroAcc[9]);
gyroy = (int16_t)(((uint16_t)gyroAcc[10]<<8) | gyroAcc[11]);
gyroz = (int16_t)(((uint16_t)gyroAcc[12]<<8) | gyroAcc[13]);
// gyroz -= 31;
LowPassFilter((float *)&gyrox,(float *)&gyroy,(float *)&gyroz);
updateFlag = 1;
yaw += gyroz*0.001/32.768f;
LED_Set(Bit_SET);
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
}
}
[/mw_shl_code]
这是在中断中积分计算陀螺仪的值
[mw_shl_code=c,true]extern float yaw;
int main()
{
uint8_t err;
float a;
SystemInit();
DelayInit();
TIM2_Configuration();
// CAN1_Configuration();
USART2_Init(57600);
LED_Configuration();
SPI2_Configuration();
DelayMs(50);
MPU9250_Init();
SPI2_ClockConfig();//?á???????±??
LowPassFilter_Init();
EKF_Init();
// DelayMs(500);
TIM2_Start();
while(1)
{
printf("%lf
",yaw);
DelayMs(10);
}
}[/mw_shl_code]
[mw_shl_code=c,true]在main函数中用串口打印陀螺仪的值[/mw_shl_code]
[mw_shl_code=c,true]但是读出陀螺仪的值偏差太大[/mw_shl_code]
[mw_shl_code=c,true]
[/mw_shl_code]
[mw_shl_code=c,true]这是开电后不动打开串口助手,然后旋转90度的情况[/mw_shl_code]
---------------------------------
这跟跟config寄存器 还有低通滤波有关系 如果开了低通滤波 输出频率是1000/(1+config)Hz
如果没有开那就跟config没关系
输出频率好像是8K? 我给忘了 看看手册 手册上都有的
一般要是焊接有问题 那应该芯片的ID读不出来的
一周热门 更多>