From 47cb0b9b645c98578eb9ec3554cf5d63bdc8b2ab Mon Sep 17 00:00:00 2001 From: crazyt Date: Mon, 17 Aug 2015 18:59:01 +0200 Subject: [PATCH] fix for wrong return value of i2c_write. --- simavr/sim/avr_twi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/simavr/sim/avr_twi.c b/simavr/sim/avr_twi.c index 629f9a4..8249ee7 100644 --- a/simavr/sim/avr_twi.c +++ b/simavr/sim/avr_twi.c @@ -308,9 +308,15 @@ avr_twi_write( p->state & TWI_COND_ACK ? TWI_MRX_ADR_ACK : TWI_MRX_ADR_NACK); } else { - _avr_twi_delay_state(p, 9, - p->state & TWI_COND_ACK ? - TWI_MTX_ADR_ACK : TWI_MTX_ADR_NACK); + if(p->state & TWI_COND_WRITE){ + _avr_twi_delay_state(p, 0, + p->state & TWI_COND_ACK ? + TWI_MTX_DATA_ACK : TWI_MTX_DATA_NACK); + }else{ + _avr_twi_delay_state(p, 9, + p->state & TWI_COND_ACK ? + TWI_MTX_ADR_ACK : TWI_MTX_ADR_NACK); + } } } p->state &= ~TWI_COND_WRITE; -- 2.39.5