From ddafbdb1e74ac6f7e8a3137482bf955cff354115 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Tue, 9 Jun 2015 14:56:37 +0100 Subject: [PATCH] twi: Always release STOP bit Seems some libraries assume this bit will autoclear, even if the stop condition was not really called for. Signed-off-by: Michel Pollet --- simavr/sim/avr_twi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/simavr/sim/avr_twi.c b/simavr/sim/avr_twi.c index 663357e..fffd86b 100644 --- a/simavr/sim/avr_twi.c +++ b/simavr/sim/avr_twi.c @@ -173,7 +173,7 @@ avr_twi_write( /*int cleared = */avr_clear_interrupt_if(avr, &p->twi, twint); // AVR_TRACE(avr, "cleared %d\n", cleared); - if (!twsto && avr_regbit_get(avr, p->twsto)) { + if (/*!twsto && */ avr_regbit_get(avr, p->twsto)) { // generate a stop condition #if AVR_TWI_DEBUG AVR_TRACE(avr, "<<<<< I2C stop\n"); @@ -182,9 +182,10 @@ avr_twi_write( if (p->state & TWI_COND_START) { avr_raise_irq(p->io.irq + TWI_IRQ_OUTPUT, avr_twi_irq_msg(TWI_COND_STOP, p->peer_addr, 1)); - avr_regbit_clear(avr, p->twsto); } } + /* clear stop condition regardless of status */ + avr_regbit_clear(avr, p->twsto); p->state = 0; } if (!twsta && avr_regbit_get(avr, p->twsta)) { -- 2.39.5