Skip to content

Commit

Permalink
Merge pull request #20299 from chrysn-pull-requests/nrf52-spi-bugs-2
Browse files Browse the repository at this point in the history
cpu/nrf52 i2c: Wait for complete transmission when writing NOSTOP
  • Loading branch information
chrysn authored Jan 27, 2024
2 parents ad69fc1 + 790e808 commit 8f111a3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cpu/nrf5x_common/periph/i2c_nrf52_nrf9160.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ static int finish(i2c_t dev, int inten_success_flag)
DEBUG("[i2c] finish: stop event occurred\n");
}

if (inten_success_flag & TWIM_INTEN_LASTTX_Msk) {
/* The interrupt is raised already when the last TX is started, but we
* have to wait until it was actually transmitted lest the transmission
* would be suppressed immediately by the next following write --
* careful here: enabling DEBUG introduces enough latency that the
* issue doesn't show up any more. */
while (bus(dev)->TXD.AMOUNT != bus(dev)->TXD.MAXCNT &&
!bus(dev)->EVENTS_ERROR) {}
}

if (bus(dev)->EVENTS_ERROR) {
bus(dev)->EVENTS_ERROR = 0;
if (bus(dev)->ERRORSRC & TWIM_ERRORSRC_ANACK_Msk) {
Expand Down

0 comments on commit 8f111a3

Please sign in to comment.