我制作了一个带有MPU-6050和STM32L072CZTx的定制板。 我的问题是,MPU-6050在成功传输后无法应答。
我在SCL和SDA上有两个4,7k上拉电阻。 重新启动MCU无法修复它。 我必须拔掉电源才能使MPU再次确认以进行传输。
我正在使用STM32 HAL,并添加了2张图片以进行澄清。
我尝试过的事情:
- 替换了MPU6050
- 降低I2C频率
- 更多...
感谢您的帮助。
HAL_StatusTypeDef writeBytes(uint8_t deviceAdd,uint8_t regAdd,uint8_t *data,uint8_t size)
{
uint8_t buffer[size + 1];
buffer[0] = regAdd;
memcpy((buffer + 1),data,size);
return HAL_I2C_Master_Transmit(&hi2c1,deviceAdd << 1,buffer,size + 1,I2C_TIMEOUT);
}
HAL_StatusTypeDef readBytes(uint8_t deviceAdd,uint8_t size)
{
return HAL_I2C_Mem_Read(&hi2c1,(uint16_t)(deviceAdd << 1),(uint16_t)regAdd,I2C_MEMADD_SIZE_8BIT,size,I2C_TIMEOUT);
}