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.3~36 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=871d22206df3a9aa47d888f88edc7dc784f12ad6;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] = {