Skip to content

Commit 9dd132d

Browse files
authored
Merge pull request #72 from davidlattimore/i2c-stop
i2c: Ensure STOP gets sent before returning
2 parents fb9c629 + d1dd6f8 commit 9dd132d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/i2c.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ macro_rules! i2c {
309309
*byte = self.i2c.rxdr.read().rxdata().bits();
310310
}
311311

312-
// automatic STOP
312+
// Wait for STOP
313+
busy_wait!(self.i2c, stopf, bit_is_set);
314+
self.i2c.icr.write(|w| w.stopcf().set_bit());
313315

314316
Ok(())
315317
}
@@ -344,7 +346,9 @@ macro_rules! i2c {
344346
self.i2c.txdr.write(|w| unsafe { w.txdata().bits(*byte) });
345347
}
346348

347-
// automatic STOP
349+
// Wait for STOP
350+
busy_wait!(self.i2c, stopf, bit_is_set);
351+
self.i2c.icr.write(|w| w.stopcf().set_bit());
348352

349353
Ok(())
350354
}
@@ -385,7 +389,9 @@ macro_rules! i2c {
385389
*byte = self.i2c.rxdr.read().rxdata().bits();
386390
}
387391

388-
// automatic STOP
392+
// Wait for STOP
393+
busy_wait!(self.i2c, stopf, bit_is_set);
394+
self.i2c.icr.write(|w| w.stopcf().set_bit());
389395

390396
Ok(())
391397
}

0 commit comments

Comments
 (0)