Skip to content

Commit c67f73c

Browse files
kapacukBOJIT
authored andcommitted
stm32: i2c-v1: Fixed a typo in i2c_read7_v1 and i2c_write7_v1
Replaced & with && Wait for all three bits to be set - SB, MSL, and BUSY. Old code worked by chance, use booleans to correctly convey intent. Reviewed-by: Karl Palsson <karlp@tweak.net.au>
1 parent af08d98 commit c67f73c

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

lib/stm32/common/i2c_common_v1.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ static void i2c_write7_v1(uint32_t i2c, int addr, uint8_t *data, size_t n)
471471

472472
i2c_send_start(i2c);
473473

474-
/* Wait for master mode selected */
475-
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
476-
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
474+
/* Wait for the end of the start condition, master mode selected, and BUSY bit set */
475+
while ( !( (I2C_SR1(i2c) & I2C_SR1_SB)
476+
&& (I2C_SR2(i2c) & I2C_SR2_MSL)
477+
&& (I2C_SR2(i2c) & I2C_SR2_BUSY) ));
477478

478479
i2c_send_7bit_address(i2c, addr, I2C_WRITE);
479480

@@ -494,9 +495,10 @@ static void i2c_read7_v1(uint32_t i2c, int addr, uint8_t *res, size_t n)
494495
i2c_send_start(i2c);
495496
i2c_enable_ack(i2c);
496497

497-
/* Wait for master mode selected */
498-
while (!((I2C_SR1(i2c) & I2C_SR1_SB)
499-
& (I2C_SR2(i2c) & (I2C_SR2_MSL | I2C_SR2_BUSY))));
498+
/* Wait for the end of the start condition, master mode selected, and BUSY bit set */
499+
while ( !( (I2C_SR1(i2c) & I2C_SR1_SB)
500+
&& (I2C_SR2(i2c) & I2C_SR2_MSL)
501+
&& (I2C_SR2(i2c) & I2C_SR2_BUSY) ));
500502

501503
i2c_send_7bit_address(i2c, addr, I2C_READ);
502504

0 commit comments

Comments
 (0)