我用的是adxl345的SINGLE_TAP 中断,可就是进不去中断是为什么
void Init_ADXL345()
{
Single_Write_ADXL345(0xA6,0x31,0x0b,1); //测量范围,正负16g,13位模式 高电平有效
Single_Write_ADXL345(0xA6,0x2C,0x08,1); //速率设定为12.5 参考pdf13页
Single_Write_ADXL345(0xA6,0x2D,0x08,1); //选择电源模式 参考pdf24页
Single_Write_ADXL345(0xA6,0x1E,0x00,1); //X 偏移量 根据测试传感器的状态写入pdf29页
Single_Write_ADXL345(0xA6,0x1F,0x00,1); //Y 偏移量 根据测试传感器的状态写入pdf29页
Single_Write_ADXL345(0xA6,0x20,0x05,1); //Z 偏移量 根据测试传感器的状态写入pdf29页
Single_Write_ADXL345(0xA6,0x1D,0x30,1); //设置THRESH_TAP(敲击门限) 62.5mg/LSB 0xff=16g 此时试取3g
Single_Write_ADXL345(0xA6,0x21,0x11,1); //设置DUR(敲击持续时间) 625us/LSB 此时试取10ms
Single_Write_ADXL345(0xA6,0x2A,0x07,1); //设置各轴方向是否参加敲击检测 xyz全参与检测
Single_Write_ADXL345(0xA6,0x2E,0x00,1); //设置中断前应先禁用中断
Single_Write_ADXL345(0xA6,0x2E,0x40,1); //使能 SINGLE_TAP 中断
Single_Write_ADXL345(0xA6,0x2F,0x40,1); //设置中断引脚映射 将单击时间映射到INT2上
}
中断是高电平有效,上升沿触发,可是不好用,为什么啊
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPD ; //配置下拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出的最大频率为50HZ
GPIO_Init(GPIOA, &GPIO_InitStructure);
///*将EXTI线6连接到PA6*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource6);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
//配置按钮中断线触发方式
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising ; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //中断线使能
EXTI_Init(&EXTI_InitStructure); //初始化中断
/* Generate software interrupt: simulate a falling edge applied on Key Button EXTI line */
EXTI_GenerateSWInterrupt(EXTI_Line6);
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //设置中断优先级
/* 开启定时器2 */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |
|