#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include "FatFs/ff.h"
#include "FatFs/diskio.h"

volatile UINT Timer;
ISR(TIMER0_COMPA_vect)
{
Timer++;
disk_timerproc();
}
// 以上FatFsで必要なタイマー割り込み
volatile unsigned char int0_cnt;
ISR(INT0_vect)
{
int0_cnt--;
release_interruption(); // ←I2Cで通信しようとするこの関数で止まる
}
volatile char usart_recvData[256];
volatile unsigned char usart_recv_write;
ISR(USART_RX_vect)
{
char x = UDR0;
usart_recvData[++usart_recv_write] = x;
}
int main(void)
{
TIMSK0 = _BV(OCIE0A);
TCCR0A = _BV(WGM01);
TCCR0B = 0b101;
OCR0A = F_CPU / 1024 / 100 - 1;

EICRA = (0<<ISC01) | (0<<ISC00);
EIMSK = 1<<INT0;

UCSR0B = 0x00;
UCSR0A = 0x00;
UCSR0C = 0b00000110;
UBRR0L = 25;
UBRR0H = 0;
UCSR0B = (1<<RXCIE0) | (0<<TXCIE0) | (1<<RXEN0) | (1<<TXEN0);

sei();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();

int0_cnt = 5;

while (1)
{
if ( int0_cnt == 0 )
{
int0_cnt = 5;
save_data();
}

sleep_mode();
}
}