From 6dd0447c12d1b75611ad8f205890913378635719 Mon Sep 17 00:00:00 2001 From: Michael Janssen Date: Tue, 6 Aug 2013 23:33:06 -0500 Subject: Bugfixes with the protocol. - Bitmasks need to be equal, not just result in non-zero - Only read status once in case it changes under us - Logical and not binary and when checking for acks on sending - We need to stop the bus when receiving the last byte - Force the bus into idle mode when we are Initing --- LUFA/Drivers/Peripheral/XMEGA/TWI_XMEGA.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'LUFA/Drivers/Peripheral/XMEGA/TWI_XMEGA.h') diff --git a/LUFA/Drivers/Peripheral/XMEGA/TWI_XMEGA.h b/LUFA/Drivers/Peripheral/XMEGA/TWI_XMEGA.h index eb8c6a5f1..0a5d477b2 100644 --- a/LUFA/Drivers/Peripheral/XMEGA/TWI_XMEGA.h +++ b/LUFA/Drivers/Peripheral/XMEGA/TWI_XMEGA.h @@ -184,8 +184,11 @@ static inline void TWI_Init(TWI_t *twi, const uint8_t Baud) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); static inline void TWI_Init(TWI_t *twi, const uint8_t Baud) { + twi->CTRL = 0x00; twi->MASTER.BAUD = Baud; - twi->MASTER.CTRLA |= TWI_MASTER_ENABLE_bm; + twi->MASTER.CTRLA = TWI_MASTER_ENABLE_bm; + twi->MASTER.CTRLB = 0; + twi->MASTER.STATUS = TWI_MASTER_BUSSTATE_IDLE_gc; } /** Turns off the TWI driver hardware. If this is called, any further TWI operations will require a call to @@ -206,7 +209,7 @@ static inline void TWI_StopTransmission(TWI_t *twi) ATTR_ALWAYS_INLINE ATTR_NON_NULL_PTR_ARG(1); static inline void TWI_StopTransmission(TWI_t *twi) { - twi->MASTER.CTRLC = TWI_MASTER_CMD_STOP_gc; + twi->MASTER.CTRLC = TWI_MASTER_ACKACT_bm | TWI_MASTER_CMD_STOP_gc; } /* Function Prototypes: */ -- cgit v1.2.3