|
本帖最后由 littleshrimp 于 2018-11-4 13:55 编辑
我做了一个测试,如果只按照你的配置方法配置LSM6DS3寄存器确实存在不能触发中断的情况
然后我在代码里增加了上电先复位LSM6DS3,然后再配置对应的寄存器,中断正常
同样,在上电不复位的情况下,在配置好寄存器以后读取一次输出寄存器,中断也正常
你可以试一下这两种方法
问题可能是器件配置好以后数据准备好,INT1引脚输出高电平,单片机因为复位等原因没有及时读取中断
再运行时中断引脚为高电平没法再次触发上升沿断中断导致
除以上两种方法还可以尝试使用高电平中断或者上升沿中断时判断一下引脚电平
测试代码:
- static uint8_t who_am_i;
- //WHO_AM_I (0Fh)
- HAL_I2C_Mem_Read(&hi2c1,0xd4,0x0f,I2C_MEMADD_SIZE_8BIT,&who_am_i,1,0x100);
- static uint8_t reg;
- //CTRL3_C (12h) 0x01 SOFT REST
- reg = 0x01;
- #warning "1.上电时复位传感器"
- // HAL_I2C_Mem_Write(&hi2c1,0xd4,0x12,I2C_MEMADD_SIZE_8BIT,®,1,0x100);
- HAL_Delay(500);
- //CTRL3_C (12h) 0x44 BDU IF_INC
- reg = 0x44;
- // HAL_I2C_Mem_Write(&hi2c1,0xd4,0x12,I2C_MEMADD_SIZE_8BIT,®,1,0x100);
- //CTRL9_XL (18h) x,y,z en
- reg = 0x38;
- HAL_I2C_Mem_Write(&hi2c1,0xd4,0x18,I2C_MEMADD_SIZE_8BIT,®,1,0x100);
- //CTRL1_XL (10h)
- reg = 0x60;
- HAL_I2C_Mem_Write(&hi2c1,0xd4,0x10,I2C_MEMADD_SIZE_8BIT,®,1,0x100);
- //INT1_CTRL (0Dh)
- reg = 0x01;
- HAL_I2C_Mem_Write(&hi2c1,0xd4,0x0d,I2C_MEMADD_SIZE_8BIT,®,1,0x100);
-
- #warning "2.配置好以后读取一次output寄存器"
- // HAL_I2C_Mem_Read(&hi2c1,0xd4,0x28,I2C_MEMADD_SIZE_8BIT,buffer,6,0x100);
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- if(lsm63se_drdy_flag)
- {
- lsm63se_drdy_flag = 0;
- HAL_I2C_Mem_Read(&hi2c1,0xd4,0x1e,I2C_MEMADD_SIZE_8BIT,&status,1,0x100);
- if(status & 0x01)
- {
- HAL_I2C_Mem_Read(&hi2c1,0xd4,0x28,I2C_MEMADD_SIZE_8BIT,buffer,6,0x100);
- }
- }
- }
- /* USER CODE END 3 */
复制代码
测试工程文件:
使用NUCLEO-L496ZG开发板,STM32CubeMX创建工程,I2C与LSM6DSL通信,CS、SA0接低电平,CS接高电平,PA5连接LSM6DS3_INT1引脚,上升沿中断,无上下拉电阻
lsm6ds3 nucleo-l496zg.rar
(9.03 MB, 下载次数: 62)
|
|