From cead7a587747652f28d0dd3eca3e00e8fb460e35 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Thu, 1 Jul 2021 14:50:51 +0200 Subject: [PATCH] cpu/sam0/i2c: Handle read with I2C_NOSTOP flag When using the I2C_NOSTOP flag the bus should remain in control. The current check assumes it must go to idle when reading. This adds a condition checks if the nostop flag is active and expects the bus status to be the owner of the bus. --- cpu/sam0_common/periph/i2c.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cpu/sam0_common/periph/i2c.c b/cpu/sam0_common/periph/i2c.c index 8d980128d4..176f9e0af6 100644 --- a/cpu/sam0_common/periph/i2c.c +++ b/cpu/sam0_common/periph/i2c.c @@ -262,8 +262,14 @@ int i2c_read_bytes(i2c_t dev, uint16_t addr, return ret; } /* Ensure all bytes has been read */ - while ((bus(dev)->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE_Msk) - != BUSSTATE_IDLE) {} + if (flags & I2C_NOSTOP) { + while ((bus(dev)->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE_Msk) + != BUSSTATE_OWNER) {} + } + else { + while ((bus(dev)->STATUS.reg & SERCOM_I2CM_STATUS_BUSSTATE_Msk) + != BUSSTATE_IDLE) {} + } /* return number of bytes sent */ return 0; }