From dd9444a7183411887b736ee66f0daf942786d29a Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Wed, 9 May 2007 15:05:01 +0000 Subject: [PATCH] Activating pull-up resistors on the ATmega168 (in addition to the ATmega8). --- targets/libraries/Wire/utility/twi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/targets/libraries/Wire/utility/twi.c b/targets/libraries/Wire/utility/twi.c index dc90b21f9..2235b0b1c 100644 --- a/targets/libraries/Wire/utility/twi.c +++ b/targets/libraries/Wire/utility/twi.c @@ -18,19 +18,19 @@ */ #include -#include +#include #include #include #include #include #include -#ifndef cbi -#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#ifndef cbi +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif - -#ifndef sbi -#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) + +#ifndef sbi +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif #include "twi.h" @@ -63,7 +63,7 @@ void twi_init(void) // initialize state twi_state = TWI_READY; - #ifdef ATMEGA8 + #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) // activate internal pull-ups for twi // as per note from atmega8 manual pg167 sbi(PORTC, 4); @@ -244,7 +244,7 @@ uint8_t twi_transmit(uint8_t* data, uint8_t length) */ void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) ) { - twi_onSlaveReceive = function; + twi_onSlaveReceive = function; } /* @@ -255,7 +255,7 @@ void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) ) */ void twi_attachSlaveTxEvent( void (*function)(void) ) { - twi_onSlaveTransmit = function; + twi_onSlaveTransmit = function; } /* @@ -267,7 +267,7 @@ void twi_attachSlaveTxEvent( void (*function)(void) ) void twi_reply(uint8_t ack) { // transmit master read ready signal, with or without ack - if(ack){ + if(ack){ TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA); }else{ TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT); @@ -286,7 +286,7 @@ void twi_stop(void) TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO); // wait for stop condition to be exectued on bus - // TWINT is not set after a stop condition! + // TWINT is not set after a stop condition! while(TWCR & _BV(TWSTO)){ continue; }