hardware: my test nrf52833 board
sensor:mpu6050 (I2C)
1、overlay file:
...
&i2c0 {
status = "okay";
sda-pin = <20>;
scl-pin = <22>;
compatible = "nordic,nrf-twi";
};
...
2、prj.conf file:...
CONFIG_I2C=y
...
3、I2C write function:
int portI2cWriteBytes(uint8_t device_i2c_addr, uint8_t reg_addr, uint8_t *data, uint32_t num_bytes)
{
uint8_t wr_addr[2];
struct i2c_msg msgs[2];
/* address */
wr_addr[0] = (reg_addr >> 8) & 0xFF;
wr_addr[1] = reg_addr & 0xFF;
/* Send the address to write to */
msgs[0].buf = wr_addr;
msgs[0].len = 2U;
msgs[0].flags = I2C_MSG_WRITE;
/* Data to be written, and STOP after this. */
msgs[1].buf = data;
msgs[1].len = num_bytes;
msgs[1].flags = I2C_MSG_WRITE | I2C_MSG_STOP;
return i2c_transfer(i2c0_dev, &msgs[0], 2, device_i2c_addr/*0x68*/);
}4、I2C read function:
int portI2cReadBytes(uint8_t device_i2c_addr, uint8_t reg_addr, uint8_t *data, uint32_t num_bytes)
{
uint8_t wr_addr[2];
struct i2c_msg msgs[2];
wr_addr[0] = (reg_addr >> 8) & 0xFF;
wr_addr[1] = reg_addr & 0xFF;
/* Send the address to read from */
msgs[0].buf = wr_addr;
msgs[0].len = 2U;
msgs[0].flags = I2C_MSG_WRITE;
/* Read from device. STOP after this. */
msgs[1].buf = data;
msgs[1].len = num_bytes;
msgs[1].flags = I2C_MSG_READ | I2C_MSG_STOP;
return i2c_transfer(i2c0_dev, &msgs[0], 2, device_i2c_addr);
}Question:
I use logic analyzer to trace, capture image like this, I can not get ACK.

But I use nrf52832(SDK17) can get ACK like this, so mpu6050 is OK.
