1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-14 11:29:26 +01:00

Activating pull-up resistors on the ATmega168 (in addition to the ATmega8).

This commit is contained in:
David A. Mellis 2007-05-09 15:05:01 +00:00
parent aa697966dc
commit dd9444a718

View File

@ -18,19 +18,19 @@
*/ */
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/signal.h> #include <avr/signal.h>
#include <compat/twi.h> #include <compat/twi.h>
#ifndef cbi #ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif #endif
#ifndef sbi #ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif #endif
#include "twi.h" #include "twi.h"
@ -63,7 +63,7 @@ void twi_init(void)
// initialize state // initialize state
twi_state = TWI_READY; twi_state = TWI_READY;
#ifdef ATMEGA8 #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__)
// activate internal pull-ups for twi // activate internal pull-ups for twi
// as per note from atmega8 manual pg167 // as per note from atmega8 manual pg167
sbi(PORTC, 4); 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) ) 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) ) 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) void twi_reply(uint8_t ack)
{ {
// transmit master read ready signal, with or without ack // transmit master read ready signal, with or without ack
if(ack){ if(ack){
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA); TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
}else{ }else{
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT); 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); TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);
// wait for stop condition to be exectued on bus // 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)){ while(TWCR & _BV(TWSTO)){
continue; continue;
} }