|
我用我的BlueCoin Starter kit开发板做了测试,开发板上的传感器是LSM6DSM配置和LSM6DSL一样
陀螺仪只需要将0x40写入ctrl2_g就可以正常工作,我在初始化时对传感器做了软复位
- //读取who am i
- uint8_t who_am_i;
- HAL_I2C_Mem_Read(&hi2c1,0xD4,0x0f,I2C_MEMADD_SIZE_8BIT,&who_am_i,1,0x100);
- while(who_am_i != 0x6a);
- //复位 CTRL3_C->SW_RESET(BIT0)
- uint8_t swreset = 1 << 0;
- HAL_I2C_Mem_Write(&hi2c1,0xD4,0x12,I2C_MEMADD_SIZE_8BIT,&swreset,1,0x100);
- //写CTRL2_G
- uint8_t ctrl2_g = 0x40;//CTRL2_G-> ODR_G2(BIT6) = 1 104 Hz 250 dps
- HAL_I2C_Mem_Write(&hi2c1,0xD4,0x11,I2C_MEMADD_SIZE_8BIT,&ctrl2_g,1,0x100);
- while(1)
- {
- //读取STATUS_REG
- HAL_I2C_Mem_Read(&hi2c1,0xD4,0x1e,I2C_MEMADD_SIZE_8BIT,&status,1,0x100);
- if(status & 0x02)
- {
- //读取OUTX_L_G=22h~OUTZ_H_G=27h
- HAL_I2C_Mem_Read(&hi2c1,0xD4,0x22,I2C_MEMADD_SIZE_8BIT,buf,6,0x100);
- x = ( ( ( ( int16_t )buf[1] ) << 8 ) + ( int16_t )buf[0] );
- y = ( ( ( ( int16_t )buf[3] ) << 8 ) + ( int16_t )buf[2] );
- z = ( ( ( ( int16_t )buf[5] ) << 8 ) + ( int16_t )buf[4] );
- }
- }
复制代码
|
|