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
1 changed files with 11 additions and 11 deletions

View File

@ -18,19 +18,19 @@
*/
#include <math.h>
#include <stdlib.h>
#include <stdlib.h>
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <compat/twi.h>
#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;
}