Skip to content

Commit 0f36f37

Browse files
committed
Add support for repeated starts in slave mode
From the data sheet TXCOMP is only set after a stop or repeated start and address change, but EOSACC is set for a stop or repeated start when the address remains the same. This change removes the check for TXCOMP when not idle, to support repeated starts for both RX and TX.
1 parent 7af5e7a commit 0f36f37

File tree

1 file changed

+18
-20
lines changed
  • hardware/arduino/sam/libraries/Wire

1 file changed

+18
-20
lines changed

hardware/arduino/sam/libraries/Wire/Wire.cpp

+18-20
Original file line numberDiff line numberDiff line change
@@ -321,27 +321,25 @@ void TwoWire::onService(void) {
321321
}
322322
}
323323

324-
if (status != SLAVE_IDLE) {
325-
if (TWI_STATUS_TXCOMP(sr) && TWI_STATUS_EOSACC(sr)) {
326-
if (status == SLAVE_RECV && onReceiveCallback) {
327-
// Copy data into rxBuffer
328-
// (allows to receive another packet while the
329-
// user program reads actual data)
330-
for (uint8_t i = 0; i < srvBufferLength; ++i)
331-
rxBuffer[i] = srvBuffer[i];
332-
rxBufferIndex = 0;
333-
rxBufferLength = srvBufferLength;
334-
335-
// Alert calling program
336-
onReceiveCallback( rxBufferLength);
337-
}
338-
339-
// Transfer completed
340-
TWI_EnableIt(twi, TWI_SR_SVACC);
341-
TWI_DisableIt(twi, TWI_IDR_RXRDY | TWI_IDR_GACC | TWI_IDR_NACK
342-
| TWI_IDR_EOSACC | TWI_IDR_SCL_WS | TWI_IER_TXCOMP);
343-
status = SLAVE_IDLE;
324+
if (status != SLAVE_IDLE && TWI_STATUS_EOSACC(sr)) {
325+
if (status == SLAVE_RECV && onReceiveCallback) {
326+
// Copy data into rxBuffer
327+
// (allows to receive another packet while the
328+
// user program reads actual data)
329+
for (uint8_t i = 0; i < srvBufferLength; ++i)
330+
rxBuffer[i] = srvBuffer[i];
331+
rxBufferIndex = 0;
332+
rxBufferLength = srvBufferLength;
333+
334+
// Alert calling program
335+
onReceiveCallback( rxBufferLength);
344336
}
337+
338+
// Transfer completed
339+
TWI_EnableIt(twi, TWI_SR_SVACC);
340+
TWI_DisableIt(twi, TWI_IDR_RXRDY | TWI_IDR_GACC | TWI_IDR_NACK
341+
| TWI_IDR_EOSACC | TWI_IDR_SCL_WS | TWI_IER_TXCOMP);
342+
status = SLAVE_IDLE;
345343
}
346344

347345
if (status == SLAVE_RECV) {

0 commit comments

Comments
 (0)