下面贴出mpu6050读写时序代码
- esp_err_t MPU6050_WriteReg(u_int8_t reg_add,u_int8_t reg_dat)
- {
- esp_err_t ret;
- i2c_cmd_handle_t cmd = i2c_cmd_link_create(); //新建操作I2C句柄
- i2c_master_start(cmd); //发出起始信号
- i2c_master_write_byte(cmd,(MPU6050_ADDRESS<<1)|I2C_MASTER_WRITE,true); //写入地址
- i2c_master_write_byte(cmd,reg_add,true); //写入寄存器地址
- i2c_master_write_byte(cmd,reg_dat,true); //写入值
- i2c_master_stop(cmd); //发出停止信号
- ret = i2c_master_cmd_begin(I2C_NUM_1,cmd,10000/portTICK_RATE_MS);
- i2c_cmd_link_delete(cmd);
- return ret;
- }
- esp_err_t MPU6050_ReadData(u_int8_t reg_add,uint8_t *data)
- {
- int ret;
- i2c_cmd_handle_t cmd = i2c_cmd_link_create(); //新建操作I2C句柄
- i2c_master_start(cmd); //启动I2C
- i2c_master_write_byte(cmd,(MPU6050_ADDRESS<<1)|I2C_MASTER_READ,1); //写入地址,选择写指令
- i2c_master_write_byte(cmd,reg_add,1); //写入寄存器地址
- i2c_master_start(cmd);
- i2c_master_read_byte(cmd,data,1); //写入寄存器地址
- i2c_master_stop(cmd);
- ret = i2c_master_cmd_begin(I2C_NUM_1,cmd,1000/portTICK_RATE_MS);
- i2c_cmd_link_delete(cmd);
- return ret;
- }
从逻辑分析仪里看的话,也没法解析
第一次用idf进行开发,希望大家可以解答一下,谢谢