From 76e0d23887b8ddc70e9afb30bb7b91e9fec96c35 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 20 Jun 2018 16:26:43 -0400 Subject: start updating i2c for timeouts --- drivers/avr/i2c_master.c | 102 +++++++++++++++++------------------------------ drivers/avr/i2c_master.h | 15 ++++--- 2 files changed, 46 insertions(+), 71 deletions(-) diff --git a/drivers/avr/i2c_master.c b/drivers/avr/i2c_master.c index 97f6900436..caca2179e0 100755 --- a/drivers/avr/i2c_master.c +++ b/drivers/avr/i2c_master.c @@ -19,24 +19,19 @@ void i2c_init(void) //TWBR = 10; } -uint8_t i2c_start(uint8_t address) +i2c_status_t i2c_start(uint8_t address, uint8_t timeout) { // reset TWI control register TWCR = 0; // transmit START condition TWCR = (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< timeout) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while( !(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while( !(TWCR & (1< I2C_TIMEOUT) { - return 2; // should make these codes standard - } + uint16_t timeout_timer = timer_read(); + while(TWCR & (1< I2C_TIMEOUT) { + return I2C_STATUS_TIMEOUT; } - #else - // wait for end of transmission - while(TWCR & (1<