|
读取程序:
int temp1[3];
int temp2[4];
u16 temp3[3];
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[0], &temp1[1], &temp1[2]);
printf("Gyro Data: %d %d %d\r\n",temp1[0],temp1[1],temp1[2]);
GPIO_ResetBits(GPIOC, GPIO_Pin_6); //D1灭
GPIO_SetBits(GPIOC, GPIO_Pin_7);// D2亮
Delay_Us(5);
ReadCmpOut(&temp2[0],&temp2[1], &temp2[2], &temp2[3]);
printf("hmc Data: %d %d %d\r\n",temp2[0],temp2[1],temp2[2]);
ReadACCDevData(&temp3[0], &temp3[1], &temp3[2]);
printf("ACC Data: %d %d %d\r\n",temp3[0],temp3[1],temp3[2]);
ReadBmpUT(0);
}
}
void ReadGyroOut(int *pwGyroX, int *pwGyroY, int *pwGyroZ)
{
unsigned char L3gWr;
unsigned char MSub;
unsigned char byData[6];
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_L 0x28 x轴低
IIC_ReadGyroData(L3gWr, MSub, byData, 6);
wTemp = 0;
wTemp = byData[1] << 8;
wTemp |= byData[0];
*pwGyroX = wTemp;
wTemp = 0;
wTemp = byData[3] << 8;
wTemp |= byData[2];
*pwGyroY = wTemp;
wTemp = 0;
wTemp = byData[5] << 8;
wTemp |= byData[4];
*pwGyroZ = wTemp;
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|