Skip to content

Commit 308137c

Browse files
authored
Merge pull request #11 from misonyo/dev
修改i2c列程rt_i2c_master_send()为rt_i2c_transfer()
2 parents 63d757d + 8c0629a commit 308137c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

i2c_aht10_sample.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ static rt_bool_t initialized = RT_FALSE; /* 传感器初始化状态 */
3131
static rt_err_t write_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint8_t *data)
3232
{
3333
rt_uint8_t buf[3];
34+
struct rt_i2c_msg msgs;
3435

3536
buf[0] = reg; //cmd
3637
buf[1] = data[0];
3738
buf[2] = data[1];
3839

40+
msgs.addr = AHT10_ADDR;
41+
msgs.flags = RT_I2C_WR;
42+
msgs.buf = buf;
43+
msgs.len = 3;
44+
3945
/* 调用I2C设备接口发送数据 */
40-
if (rt_i2c_master_send(bus, AHT10_ADDR, 0, buf, 3) == 3)
46+
if (rt_i2c_transfer(bus, &msgs, 1) == 1)
4147
return RT_EOK;
4248
else
4349
return -RT_ERROR;
@@ -53,7 +59,7 @@ static rt_err_t read_regs(struct rt_i2c_bus_device *bus, rt_uint8_t len, rt_uint
5359
msgs.buf = buf;
5460
msgs.len = len;
5561

56-
/* 调用I2C设备接口发送数据 */
62+
/* 调用I2C设备接口接收数据 */
5763
if (rt_i2c_transfer(bus, &msgs, 1) == 1)
5864
return RT_EOK;
5965
else
@@ -78,7 +84,7 @@ static void aht10_init(const char *name)
7884
rt_uint8_t temp[2] = {0, 0};
7985

8086
/* 查找I2C总线设备,获取I2C总线设备句柄 */
81-
i2c_bus = rt_i2c_bus_device_find(name);
87+
i2c_bus = (struct rt_i2c_bus_device *)rt_device_find(name);
8288

8389
if (i2c_bus == RT_NULL)
8490
{

0 commit comments

Comments
 (0)