From cba6a81a73d351bea164dff2daab64b0ffefa98c Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Thu, 2 Jul 2015 08:56:34 +0200 Subject: [PATCH] kinetis: i2c: only send STOP in _i2c_stop() --- cpu/kinetis_common/i2c.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cpu/kinetis_common/i2c.c b/cpu/kinetis_common/i2c.c index a35de4a55b..c6f70828c5 100644 --- a/cpu/kinetis_common/i2c.c +++ b/cpu/kinetis_common/i2c.c @@ -215,11 +215,11 @@ static inline int _i2c_receive(I2C_Type *dev, uint8_t *data, int length) dev->C1 = I2C_C1_IICEN_MASK | I2C_C1_MST_MASK; if (length == 1) { - /* no ack signal */ + /* Send NACK after receiving the next byte */ dev->C1 |= I2C_C1_TXAK_MASK; } - /* dummy read */ + /* Initiate master receive mode by reading the data register */ dev->D; while (length > 0) { @@ -227,18 +227,14 @@ static inline int _i2c_receive(I2C_Type *dev, uint8_t *data, int length) dev->S = I2C_S_IICIF_MASK; - if (length == 2) { - /* no ack signal is sent on the following receiving byte */ + length--; + + if (length == 1) { + /* Send NACK after receiving the next byte */ dev->C1 |= I2C_C1_TXAK_MASK; } - if (length == 1) { - /* generate stop */ - dev->C1 &= ~I2C_C1_MST_MASK; - } - data[n] = (char)dev->D; - length--; n++; }