时钟我用的是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; //¶Á³öÊý¾Ý³ýÒÔÁ¿³Ì
}
}
各位大神看看是哪有问题,不甚感激!
此帖出自小平头技术问答
{
L3GD20_InitTypeDef L3GD20_InitStructure;
L3GD20_FilterConfigTypeDef L3GD20_FilterConfigStructure;
L3GD20_InitStructure.Power_Mode=L3GD20_MODE_ACTIVE;//L3GD20_MODE_POWERDOWN;
L3GD20_InitStructure.Output_DataRate=L3GD20_OUTPUT_DATARATE_1;
L3GD20_InitStructure.Axes_Enable=L3GD20_AXES_ENABLE;
L3GD20_InitStructure.Band_Width=L3GD20_BANDWIDTH_4;
L3GD20_InitStructure.BlockData_Update=L3GD20_BlockDataUpdate_Continous;//L3GD20_BlockDataUpdate_Single;
L3GD20_InitStructure.Endianness=L3GD20_BLE_MSB;//ÏÈ´Ó¸ßλ·¢ËÍ
L3GD20_InitStructure.Full_Scale=L3GD20_FULLSCALE_500;
L3GD20_Init(&L3GD20_InitStructure);
L3GD20_FilterConfigStructure.HighPassFilter_Mode_Selection=L3GD20_HPM_AUTORESET_INT;// L3GD20_HPM_NORMAL_MODE;
L3GD20_FilterConfigStructure.HighPassFilter_CutOff_Frequency=L3GD20_HPFCF_0;
L3GD20_FilterConfig(&L3GD20_FilterConfigStructure);
//L3GD20_InterruptConfigStructure.Latch_Request=
//L3GD20_InterruptConfigStructure.Interrupt_Axes=
//L3GD20_InterruptConfigStructure.Interrupt_ActiveEdge=L3GD20_INT1INTERRUPT_HIGH_EDGE;
}
int main(void)
{
RCC_configuration();
//RCC_GetClocksFreq(&clock);
gyro_Config();
while (1)
{
//L3GD20_Read(l3gd20_id,L3GD20_ID,1);//¶ÁÈ¡ÍÓÂÝÒǵÄID
//L3GD20_Read(tmp,L3GD20_CTRL_REG4_ADDR,1);
//L3GD20_Read(tmpbuffer,L3GD20_OUT_X_L_ADDR,6);
Gyro_ReadAngRate(GyroBuffer);
}
}
一周热门 更多>