Skip to content

Commit a72b50c

Browse files
authored
Stop I2C bus with a timeout
1 parent f2babd5 commit a72b50c

File tree

1 file changed

+7
-2
lines changed
  • libraries/Wire/src/utility

1 file changed

+7
-2
lines changed

libraries/Wire/src/utility/twi.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,13 @@ static int i2c_stop(i2c_t *obj)
174174
/* generate a STOP condition */
175175
i2c_stop_on_bus(obj_s->i2c);
176176

177-
/* wait for STOP bit reset */
178-
while((I2C_CTL0(obj_s->i2c) & I2C_CTL0_STOP));
177+
/* wait for STOP bit reset with timeout */
178+
int timeout = FLAG_TIMEOUT;
179+
while((I2C_CTL0(obj_s->i2c) & I2C_CTL0_STOP)) {
180+
if ((timeout--) == 0) {
181+
return I2C_ERROR_BUS_BUSY;
182+
}
183+
}
179184

180185
return 0;
181186
}

0 commit comments

Comments
 (0)