时钟我用的是HSI(36mhz),使用SPI读取L3GA20的值,在调试时,全速运行时感觉会卡,单步运行没问题,陀螺仪的数据不会变?
void Gyro_ReadAngRate (float* pfData)
{
uint8_t tmpbuffer[6] ={0};
int16_t RawData[3] = {0};
uint8_t tmpreg = 0;
float sensitivity = 0;
int i =0;
L3GD20_Read(&tmpreg,L3GD20_CTRL_REG4_ADDR,1);
L3GD20_Read(tmpbuffer,L3GD20_OUT_X_L_ADDR,6);
if(!(tmpreg & 0x40))
{
for(i=0; i<3; i++)
{
RawData
=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);//ÏȶÁµÍλ
}
}
else
{
for(i=0; i<3; i++)
{
RawData=(int16_t)(((uint16_t)tmpbuffer[2*i] << 8) + tmpbuffer[2*i+1]);//ÏȶÁ¸ßλ
}
}
switch(tmpreg & 0x30)
{
case 0x00:
sensitivity=L3G_Sensitivity_250dps; //L3G_Sensitivity_500dps=360/pi
break;
case 0x10:
sensitivity=L3G_Sensitivity_500dps; //L3G_Sensitivity_500dps=180/pi=57.1429
break;
case 0x20:
sensitivity=L3G_Sensitivity_2000dps;//L3G_Sensitivity_500dps=1/4*180/pi
break;
}
for(i=0; i<3; i++)
{
pfData=(float)RawData/sensitivity; //¶Á³öÊý¾Ý³ýÒÔÁ¿³Ì
}
}
各位大神看看是哪有问题,不甚感激!
此帖出自小平头技术问答
一周热门 更多>