Skip to content

Commit bc0e699

Browse files
committed
don't forget operating slave address or the bitrate when we reset because of a timeout
1 parent 6127423 commit bc0e699

File tree

1 file changed

+11
-0
lines changed
  • libraries/Wire/src/utility

1 file changed

+11
-0
lines changed

libraries/Wire/src/utility/twi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,19 @@ void twi_setTimeoutInMicros(uint16_t timeout)
443443
*/
444444
void twi_handleTimeout(void)
445445
{
446+
// remember the bitrate register value
447+
uint8_t previous_TWBR = TWBR;
448+
449+
// remember the address register value
450+
uint8_t previous_TWAR = TWBR;
451+
452+
// reset the interface
446453
twi_disable();
447454
twi_init();
455+
456+
// reapply the previous register values
457+
TWAR = previous_TWAR;
458+
TWBR = previous_TWAR;
448459
}
449460

450461
ISR(TWI_vect)

0 commit comments

Comments
 (0)