Skip to content

Commit 94df478

Browse files
BootloaderTest: Remove ackLastRead
Turns out that acking the last read is actually problematic for the I²C protocol, since then the slave does not know the transfer is completed and might pull SDA down. This prevents the master from sending a stop condition. In practice, this did not happen because the slave politely withdraws from the bus when its last databyte is sent, but it is not required to do so.
1 parent 97c8fba commit 94df478

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

BootloaderTest/BootloaderTest.ino

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct Cfg {
5050

5151
bool repStartAfterWrite = false;
5252
bool repStartAfterRead = false;
53-
bool ackLastRead = false;
5453
bool skipWrite = false;
5554

5655
// These are not changed, so set them here
@@ -112,10 +111,7 @@ bool read_status(uint8_t *status, uint8_t *datain, uint8_t okLen, uint8_t failLe
112111
assertAck(bus.readThenAck(datain[i]));
113112

114113
uint8_t crc;
115-
if (cfg.ackLastRead)
116-
assertAck(bus.readThenAck(crc));
117-
else
118-
assertAck(bus.readThenNack(crc));
114+
assertAck(bus.readThenNack(crc));
119115

120116
uint8_t expectedCrc = Crc().update(*status).update(len).update(datain, expectedLen).get();
121117
assertEqual(crc, expectedCrc);
@@ -608,8 +604,6 @@ void runTests() {
608604
Serial.println("using repstart after write");
609605
if (cfg.repStartAfterRead)
610606
Serial.println("using repstart after read");
611-
if (cfg.ackLastRead)
612-
Serial.println("acking last read");
613607

614608
bus.print = cfg.printRawData;
615609

@@ -627,7 +621,6 @@ void runTests() {
627621
// Randomly change these values on every run
628622
cfg.repStartAfterWrite = random(2);
629623
cfg.repStartAfterRead = random(2);
630-
cfg.ackLastRead = random(2);
631624
}
632625

633626
void runFixedTests() {
@@ -638,7 +631,6 @@ void runFixedTests() {
638631
cfg.skipWrite = false;
639632
cfg.repStartAfterWrite = false;
640633
cfg.repStartAfterRead = false;
641-
cfg.ackLastRead = false;
642634
cfg.setAddr = 0;
643635

644636
// Run the tests for all allowed I2c addresses, without changing the

PROTOCOL.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ line is controlled by the slave.
4141

4242
Acks and nacks are omitted from this table, but are present after each
4343
byte. All bytes should be acked by the other party than the one that
44-
sent the data. A nack should always mean the end of the transfer, but
45-
the last byte in a transfer does not need to be acked (though it
46-
typically is in a read transfer).
44+
sent the data. The last byte in a read transfer should always be acked
45+
by the master, so the slave knows to release the bus.
4746

4847
The maximum read or write length is 32 bytes (excluding address, including
4948
everything else).

0 commit comments

Comments
 (0)