@@ -332,27 +332,25 @@ void TwoWire::onService(void) {
332332 }
333333 }
334334
335- if (status != SLAVE_IDLE) {
336- if (TWI_STATUS_TXCOMP (sr) && TWI_STATUS_EOSACC (sr)) {
337- if (status == SLAVE_RECV && onReceiveCallback) {
338- // Copy data into rxBuffer
339- // (allows to receive another packet while the
340- // user program reads actual data)
341- for (uint8_t i = 0 ; i < srvBufferLength; ++i)
342- rxBuffer[i] = srvBuffer[i];
343- rxBufferIndex = 0 ;
344- rxBufferLength = srvBufferLength;
345-
346- // Alert calling program
347- onReceiveCallback ( rxBufferLength);
348- }
349-
350- // Transfer completed
351- TWI_EnableIt (twi, TWI_SR_SVACC);
352- TWI_DisableIt (twi, TWI_IDR_RXRDY | TWI_IDR_GACC | TWI_IDR_NACK
353- | TWI_IDR_EOSACC | TWI_IDR_SCL_WS | TWI_IER_TXCOMP);
354- status = SLAVE_IDLE;
335+ if (status != SLAVE_IDLE && TWI_STATUS_EOSACC (sr)) {
336+ if (status == SLAVE_RECV && onReceiveCallback) {
337+ // Copy data into rxBuffer
338+ // (allows to receive another packet while the
339+ // user program reads actual data)
340+ for (uint8_t i = 0 ; i < srvBufferLength; ++i)
341+ rxBuffer[i] = srvBuffer[i];
342+ rxBufferIndex = 0 ;
343+ rxBufferLength = srvBufferLength;
344+
345+ // Alert calling program
346+ onReceiveCallback ( rxBufferLength);
355347 }
348+
349+ // Transfer completed
350+ TWI_EnableIt (twi, TWI_SR_SVACC);
351+ TWI_DisableIt (twi, TWI_IDR_RXRDY | TWI_IDR_GACC | TWI_IDR_NACK
352+ | TWI_IDR_EOSACC | TWI_IDR_SCL_WS | TWI_IER_TXCOMP);
353+ status = SLAVE_IDLE;
356354 }
357355
358356 if (status == SLAVE_RECV) {
0 commit comments