高级会员
- 积分
- 808
- 威望
- 418
- 贡献
- 212
- 兑换币
- 229
- 注册时间
- 2013-3-1
- 在线时间
- 89 小时
|
用k60调试陀螺仪,数值一直无变化,求助啊
附上程序:
#define WHO_AM_I 0x0F
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24
#define OUT_X_L 0x28
#define OUT_X_H 0x29
#define OUT_Y_L 0x2A
#define OUT_Y_H 0x2B
#define OUT_Z_L 0x2C
#define OUT_Z_H 0x2D
#define SlaveAddress1 0xD2
void L3G400D_Init()
{ I2C_init(I2C0);
I2C_WriteAddr(I2C0, SlaveAddress1, CTRL_REG1, 0x0f); //
I2C_WriteAddr(I2C0, SlaveAddress1, CTRL_REG2, 0x00); //
I2C_WriteAddr(I2C0, SlaveAddress1, CTRL_REG3, 0x08); //
I2C_WriteAddr(I2C0, SlaveAddress1, CTRL_REG4, 0x30); //
I2C_WriteAddr(I2C0, SlaveAddress1, CTRL_REG5, 0x00); //
}
void main()
{ uart_init (UART1,115200);
L3G400D_Init();
while(1)
{
buf[0] = I2C_ReadAddr(I2C0, SlaveAddress1, OUT_X_L);//buf[]是u8型的
buf[1] = I2C_ReadAddr(I2C0, SlaveAddress1, OUT_X_H);
temp=buf[1]<<8+buf[0];//temp是int型的
printf("%d\n",temp);
}
}
|
|