0,0 → 1,62 |
//############################################################################ |
// - PPM2PentaxIR Uart for Debug only |
// - ATMEGA8 mit 8MHz |
// - Nur für den privaten Gebrauch |
// - Keine Garantie auf Fehlerfreiheit |
// - Kommerzielle Nutzung nur mit meiner Zustimmung |
// - walter Meyer @ www.freakware.de |
//############################################################################*/ |
#include <avr/io.h> |
#include <util/twi.h> |
#include "main.h" |
#include "twislave.h" |
|
unsigned char I2C_IN; |
|
|
//############################################################################ |
//I2C (TWI) Interface Init |
void StartI2C(void) |
//############################################################################ |
{ |
TWAR = 0x62; //I2C client address |
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA); |
} |
|
//############################################################################ |
//ISR, die bei einem Ereignis auf dem Bus ausgelöst wird. Im Register TWSR befindet |
//sich dann ein Statuscode, anhand dessen die Situation festgestellt werden kann. |
SIGNAL (TWI_vect) |
//############################################################################ |
{ |
switch (TWSR & 0xF8) |
{ |
case SR_SLA_ACK: |
TWCR |= (1<<TWINT); |
return; |
|
case SR_PREV_ACK: //receive |
I2C_IN = TWDR; |
TWCR |= (1<<TWINT); |
return; |
|
case SW_SLA_ACK: //send 0x00 |
TWDR = 0x00; |
TWCR |= (1<<TWINT); |
return; |
|
case SW_DATA_ACK: //send 0x00 |
TWDR = 0x00; |
TWCR |= (1<<TWINT); |
return; |
|
case TWI_BUS_ERR_2: //bus error / reset bus |
TWCR |=(1<<TWSTO) | (1<<TWINT); |
|
case TWI_BUS_ERR_1: //bus error / reset bus |
TWCR |=(1<<TWSTO) | (1<<TWINT); |
} |
TWCR =(1<<TWEA) | (1<<TWINT) | (1<<TWEN) | (1<<TWIE); // TWI Reset |
} |
|
|