#include <avr/io.h>
+#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "usart.h"
int main(void)
{
- uint8_t pb = 0x00;
- int8_t dir = 1;
- volatile uint16_t i;
-
DDRB = 0xff;
+ PORTB = 0xff;
usart_init();
+ printf("\n");
+
i2c_init();
+ printf("Waiting for I2C...\n");
+
sei();
- printf("Hallo!\n");
+ PORTB = 0xff;
while(1) {
- pb += dir;
- PORTB = pb;
-
- for (i = 0; i < (pb<<5); i++) {}
-
- if ((pb == 0) || (pb == 0xff))
- dir = -dir;
+#if 1
+ sleep_mode();
+#endif
}
return 0;
void i2c_init()
{
- TWAR = BMC_ADDR;
- TWCR &= ~(1<<TWSTA)|(1<<TWSTO);
- TWCR|= (1<<TWEA) | (1<<TWEN)|(1<<TWIE);
+ TWAR = BMC_ADDR & 0xfe;
+ TWDR = 0x00;
+ TWCR &= ~((1<<TWSTA) | (1<<TWSTO));
+ TWCR |= ((1<<TWEA) | (1<<TWEN) | (1<<TWIE));
+ printf("Status: 0x%02x\n", TW_STATUS);
+ PORTC = 0x03;
}
-ISR (TWI_vect)
+ISR (TWI_vect, ISR_BLOCK)
{
- printf("Interrupt, Status: %02x!\n", TW_STATUS);
+ printf("Interrupt, Status: 0x%02x, Data: 0x%02x!\n", TW_STATUS, TWDR);
switch (TW_STATUS) {
default:
- TWCR_RESET;
+ TWCR_ACK;
break;
}
}