modify sda pin direction for read.

This commit is contained in:
Thomas Klaehn 2019-07-25 14:22:15 +02:00
parent 1c436eab6c
commit d018e6e6b2

View File

@ -23,7 +23,9 @@ int i2c_open(const struct i2c_bb *i2c)
assert(NULL != i2c);
res = gpio_open(i2c->sda);
res |= gpio_direction(i2c->sda, OUT);
res |= gpio_open(i2c->scl);
res |= gpio_direction(i2c->scl, OUT);
res |= gpio_write(i2c->sda, 1);
res |= gpio_write(i2c->scl, 1);
@ -168,9 +170,11 @@ static uint8_t read_bit(const struct i2c_bb *i2c)
gpio_write(i2c->sda, 1);
usleep(5);
gpio_write(i2c->scl, 1);
gpio_direction(i2c->sda, IN);
usleep(5);
res = gpio_read(i2c->sda);
gpio_write(i2c->scl, 0);
gpio_direction(i2c->sda, OUT);
if(res < 0) {
res = 0;