From 2a17b025420033ec372550d709c00d8f7bb9e120 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 31 Oct 2017 13:28:56 +0000 Subject: Fixed bug #900. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10921 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/lib/fallback/I2C/hal_i2c_lld.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'os/hal/lib/fallback/I2C/hal_i2c_lld.c') diff --git a/os/hal/lib/fallback/I2C/hal_i2c_lld.c b/os/hal/lib/fallback/I2C/hal_i2c_lld.c index 77b9e2e29..72e522b6f 100644 --- a/os/hal/lib/fallback/I2C/hal_i2c_lld.c +++ b/os/hal/lib/fallback/I2C/hal_i2c_lld.c @@ -241,8 +241,6 @@ static msg_t i2c_read_byte(I2CDriver *i2cp, unsigned nack) { static msg_t i2c_write_header(I2CDriver *i2cp, i2caddr_t addr, bool rw) { - CHECK_ERROR(i2c_write_start(i2cp)); - /* Check for 10 bits addressing.*/ if (i2cp->config->addr10) { /* It is 10 bits.*/ @@ -358,6 +356,8 @@ msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr, i2cp->end += timeout; } + CHECK_ERROR(i2c_write_start(i2cp)); + /* Sending anddress and mode.*/ CHECK_ERROR(i2c_write_header(i2cp, addr, true)); @@ -408,6 +408,9 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, i2cp->end += timeout; } + /* send start condition */ + CHECK_ERROR(i2c_write_start(i2cp)); + /* Sending anddress and mode.*/ CHECK_ERROR(i2c_write_header(i2cp, addr, false)); @@ -417,7 +420,12 @@ msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, /* Is there a read phase? */ if (rxbytes > 0U) { + + /* send restart condition */ CHECK_ERROR(i2c_write_restart(i2cp)); + /* Sending anddress and mode.*/ + CHECK_ERROR(i2c_write_header(i2cp, addr, true)); + do { /* Last byte sends a NACK.*/ msg_t msg = i2c_read_byte(i2cp, rxbytes > 1U ? 0U : 1U); -- cgit v1.2.3