/*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");
}
/* 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)) {
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
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] = {