Commit ddafbdb1e74ac6f7e8a3137482bf955cff354115
authorMichel Pollet <buserror@gmail.com>
Tue, 9 Jun 2015 13:56:37 +0000 (14:56 +0100)
committerMichel Pollet <buserror@gmail.com>
Tue, 9 Jun 2015 13:56:37 +0000 (14:56 +0100)
Seems some libraries assume this bit will autoclear, even if
the stop condition was not really called for.

Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr/sim/avr_twi.c

index 663357e90801164a4f60910af76684aba0f9fa44..fffd86b32c5a5d21138c6909b713dc7e9ebe6a80 100644 (file)
@@ -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)) {