本帖最后由 得嘞 于 2016-11-29 19:11 编辑
//************L3G4200D.c*********************************
#include "l3g4200d.h"
#include "sys.h"
#include "delay.h"
#include "math.h"
u8 Init_L3G4200D(void)
{
IIC_Init1();
Single_Write(CTRL_REG1,0x0F);
Single_Write(CTRL_REG2,0x00);
Single_Write(CTRL_REG3,0x00);
Single_Write(CTRL_REG4,0x30); //+-2000dps
Single_Write(CTRL_REG5,0x00);
return 0;
}
void Single_Write(u8 REG_Address,u8 REG_data) //void
{
IIC_Start1();
IIC_Send_Byte1(L3G4200_read);
IIC_Wait_Ack1();
IIC_Send_Byte1(REG_Address);
IIC_Wait_Ack1();
IIC_Send_Byte1(REG_data);
IIC_Wait_Ack1();
IIC_Stop1();
}
//?????*****************************************Single_ReadL3G4200DREG_data
u8 Single_Read(u8 REG_Address)
{
u8 REG_data=0;
IIC_Start1();
IIC_Send_Byte1(L3G4200_WRITE);
IIC_Wait_Ack1();
IIC_Send_Byte1(REG_Address);
IIC_Wait_Ack1();
IIC_Start1();
IIC_Send_Byte1(L3G4200_read);
IIC_Wait_Ack1();
REG_data=IIC_Read_Byte1(0);
IIC_Stop1();
return REG_data;
}
void READ_L3G4200D(short *tlx,short *tly,short *tlz)
{
u8 BUF[6];
u8 i;
*tlx=0;
*tly=0;
*tlz=0;
IIC_Start1();
IIC_Send_Byte1(L3G4200_WRITE);
IIC_Wait_Ack1();
IIC_Send_Byte1(0x80|0x28);
IIC_Wait_Ack1();
IIC_Start1();
IIC_Send_Byte1(L3G4200_read);
IIC_Wait_Ack1();
for(i=0;i<6;i++)
{
if(i==5)BUF=IIC_Read_Byte1(0);
else BUF=IIC_Read_Byte1(1);
}
IIC_Stop1();
*tlx=(short)(((u16)BUF[1]<<8)+BUF[0]);
*tly=(short)(((u16)BUF[3]<<8)+BUF[2]);
*tlz=(short)(((u16)BUF[5]<<8)+BUF[4]);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
void Single_Write(u8 REG_Address,u8 REG_data) //void
{
IIC_Start1();
IIC_Send_Byte1(L3G4200_read); --------------这里这里-------改成------- IIC_Send_Byte1(L3G4200_WRITE);
IIC_Wait_Ack1();
IIC_Send_Byte1(REG_Address);
IIC_Wait_Ack1();
IIC_Send_Byte1(REG_data);
IIC_Wait_Ack1();
IIC_Stop1();
}
一周热门 更多>