[mw_shl_code=c,true] while(ADXL345_Init()) //3D加速度传感器初始化
{
printf("ADXL345 Error
");
delay_ms(200);
delay_ms(200);
LED_GREEN_flash = 0;
}
printf("ADXL345 OK
");
[/mw_shl_code]
[mw_shl_code=c,true] ADXL345_Read_Average(&x,&y,&z,10);
// ADXL345_RD_XYZ(&Acceleration_x,&Acceleration_y,&Acceleration_z);
printf("x = %d
",x);
printf("y = %d
",y);
printf("z = %d
",z);
delay_ms(50);
[/mw_shl_code]
50ms读取输出一次 代码是战舰版复制过来的
x = 17y = 0z = 0
x = 17y = 0z = 0
x = 17y = 0z = 0
x = 15y = 0z = 0
x = 17y = 0z = 0
x = 17y = 0z = 0
x = 18y = 0z = 0
x = 17y = 0z = 0
x = 16y = 0z = 0
x = 17y = 0z = 0
x = 16y = 0z = 0
x = 17y = 0z = 0
打印出来就是这个样子 y和z一直是0 变化板子时 只有x变化
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
这是 电路图
SCL -----PB1
INT1-----PB12
INT0-----PB13
[mw_shl_code=c,true] void IIC_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; //RCC->APB2ENR|=1<<4;//?????????èIO PORTB?±?? RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); //SDA PB0 SCL PB1 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ; //???ì???? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1); //PE.5 ?????? IIC_SCL=1; IIC_SDA=1; }[/mw_shl_code]
[mw_shl_code=c,true]#define SDA_IN() {GPIOB->CRL&=0XFFFFFFF0;GPIOB->CRL|=8<<0;} #define SDA_OUT() {GPIOB->CRL&=0XFFFFFFF0;GPIOB->CRL|=3<<0;} #define IIC_SCL PBout(1) //SCL #define IIC_SDA PBout(0) //SDA #define READ_SDA PBin(0) //????SDA [/mw_shl_code]
还有什么地方是不对的 求解
---------------------------------
应该是这个问题了 看来只能这样了
---------------------------------
自己顶下
一周热门 更多>