From: Michel Pollet Date: Wed, 10 Jun 2015 20:00:38 +0000 (+0100) Subject: twi: Revert to NO_STATE after a stop X-Git-Tag: v1.6~72 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=8d291ede8e5f76db9523109ffdd1f3771949b54d;p=sx%2Fsimavr.git twi: Revert to NO_STATE after a stop Otherwise the interrupt might get re-triggered Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/avr_twi.c b/simavr/sim/avr_twi.c index fffd86b..c13be6c 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"); @@ -186,6 +186,7 @@ avr_twi_write( } /* clear stop condition regardless of status */ avr_regbit_clear(avr, p->twsto); + _avr_twi_status_set(p, TWI_NO_STATE, 0); p->state = 0; } if (!twsta && avr_regbit_get(avr, p->twsta)) { @@ -286,7 +287,7 @@ avr_twi_write( else AVR_TRACE(avr, "I2C latch is not ready, do nothing\n"); #endif - } else { + } else if (p->state) { #if AVR_TWI_DEBUG AVR_TRACE(avr, "I2C Master address %02x\n", avr->data[p->r_twdr]); #endif @@ -452,6 +453,7 @@ void avr_twi_reset(struct avr_io_t *io) avr_twi_t * p = (avr_twi_t *)io; avr_irq_register_notify(p->io.irq + TWI_IRQ_INPUT, avr_twi_irq_input, p); p->state = p->peer_addr = 0; + avr_regbit_setto_raw(p->io.avr, p->twsr, TWI_NO_STATE); } static const char * irq_names[TWI_IRQ_COUNT] = {