stm32读传感器数据不变
读取程序:int temp1;
int temp2;
u16 temp3;
unsigned char m;
main()
{
ChipHardwareInit();
InitGyro();
InitCmp();
InitACCDev();
BMP_Init();
while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_6);// D1亮
Delay_Us(1);
printf("HY-STM32 \n\r");
ReadGyroOut(&temp1, &temp1, &temp1);
printf("Gyro Data: %d %d %d\r\n",temp1,temp1,temp1);
GPIO_ResetBits(GPIOC, GPIO_Pin_6); //D1灭
GPIO_SetBits(GPIOC, GPIO_Pin_7);// D2亮
Delay_Us(5);
ReadCmpOut(&temp2,&temp2, &temp2, &temp2);
printf("hmc Data: %d %d %d\r\n",temp2,temp2,temp2);
ReadACCDevData(&temp3, &temp3, &temp3);
printf("ACC Data: %d %d %d\r\n",temp3,temp3,temp3);
ReadBmpUT(0);
}
}
void ReadGyroOut(int *pwGyroX, int *pwGyroY, int *pwGyroZ)
{
unsigned char L3gWr;
unsigned char MSub;
unsigned char byData;
unsigned int wTemp;
L3gWr = L3G_IIC_ADDR << 1; //0x68
L3gWr = L3gWr | WRITE_L3G; //WRITE_L3G 0x0
MSub = 0x80 | OUT_X_L; // 0x80 : multiple read OUT_X_L0x28x轴低
IIC_ReadGyroData(L3gWr, MSub, byData, 6);
wTemp= 0;
wTemp = byData << 8;
wTemp |= byData;
*pwGyroX = wTemp;
wTemp= 0;
wTemp = byData << 8;
wTemp |= byData;
*pwGyroY = wTemp;
wTemp= 0;
wTemp = byData << 8;
wTemp |= byData;
*pwGyroZ = wTemp;
}
页:
[1]