From b788541308e240fa123f2a521ea43067304e081f Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 31 Jul 2019 19:44:23 +0200 Subject: [PATCH] freescale: fix i2c_byte_read function --- .../TARGET_MCUXpresso_MCUS/api/i2c_api.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c index ff6fc2a856..1453e4239a 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c @@ -192,10 +192,8 @@ int i2c_byte_read(i2c_t *obj, int last) base->C1 |= I2C_C1_TXAK_MASK; // NACK } - data = (base->D & 0xFF); - - /* Change direction to Tx to avoid extra clocks. */ - base->C1 |= I2C_C1_TX_MASK; + /* Read dummy to release the bus. */ + data = base->D; /* Wait until data transfer complete. */ while (!(base->S & kI2C_IntPendingFlag)) @@ -205,6 +203,11 @@ int i2c_byte_read(i2c_t *obj, int last) /* Clear the IICIF flag. */ base->S = kI2C_IntPendingFlag; + /* Change direction to Tx to avoid extra clocks. */ + base->C1 |= I2C_C1_TX_MASK; + + data = (base->D & 0xFF); + return data; }