Interupts

Actually, as a side effect of my plan to put the arduino in sleep, i have read a bit into interrupts to wake the thing up again. I haven't test it yet, but basically, you have to use the interrupt.h header file from Arduino-0006/tools/avr/avr/include/avr/ and copy it in a same named folder in the Arduino-0006/lib/targets/libraries/ folder.

Include it in your sketch like this:

#include interrupt.h

then you can turn interrups on with

sei();

and turn it off again with

cli();

don't leave it on forever, otherwise yor program will be interrupted on moments you dont want to.

then your interrupt routines will have a form of:

ISR(_interrupt_vecor_name_){

// code here

}

where interrupt_vector_name is filled in with the apropiate interrupt you want.

these names are defined in the iom8.h file in two different forms. pick the one you like:

/* Interrupt vectors */

/* External Interrupt Request 0 */
#define INT0_vect                  _VECTOR(1)
#define SIG_INTERRUPT0                  _VECTOR(1)

/* External Interrupt Request 1 */
#define INT1_vect                  _VECTOR(2)
#define SIG_INTERRUPT1                  _VECTOR(2)

/* Timer/Counter2 Compare Match */
#define TIMER2_COMP_vect            _VECTOR(3)
#define SIG_OUTPUT_COMPARE2            _VECTOR(3)

/* Timer/Counter2 Overflow */
#define TIMER2_OVF_vect                  _VECTOR(4)
#define SIG_OVERFLOW2                  _VECTOR(4)

/* Timer/Counter1 Capture Event */
#define TIMER1_CAPT_vect            _VECTOR(5)
#define SIG_INPUT_CAPTURE1            _VECTOR(5)

/* Timer/Counter1 Compare Match A */
#define TIMER1_COMPA_vect            _VECTOR(6)
#define SIG_OUTPUT_COMPARE1A            _VECTOR(6)

/* Timer/Counter1 Compare Match B */
#define TIMER1_COMPB_vect            _VECTOR(7)
#define SIG_OUTPUT_COMPARE1B            _VECTOR(7)

/* Timer/Counter1 Overflow */
#define TIMER1_OVF_vect                  _VECTOR(8)
#define SIG_OVERFLOW1                  _VECTOR(8)

/* Timer/Counter0 Overflow */
#define TIMER0_OVF_vect                  _VECTOR(9)
#define SIG_OVERFLOW0                  _VECTOR(9)

/* Serial Transfer Complete */
#define SPI_STC_vect                  _VECTOR(10)
#define SIG_SPI                        _VECTOR(10)

/* USART, Rx Complete */
#define USART_RXC_vect                  _VECTOR(11)
#define SIG_UART_RECV                  _VECTOR(11)

/* USART Data Register Empty */
#define USART_UDRE_vect                  _VECTOR(12)
#define SIG_UART_DATA                  _VECTOR(12)

/* USART, Tx Complete */
#define USART_TXC_vect                  _VECTOR(13)
#define SIG_UART_TRANS                  _VECTOR(13)

/* ADC Conversion Complete */
#define ADC_vect                  _VECTOR(14)
#define SIG_ADC                        _VECTOR(14)

/* EEPROM Ready */
#define EE_RDY_vect                  _VECTOR(15)
#define SIG_EEPROM_READY            _VECTOR(15)

/* Analog Comparator */
#define ANA_COMP_vect                  _VECTOR(16)
#define SIG_COMPARATOR                  _VECTOR(16)

/* 2-wire Serial Interface */
#define TWI_vect                  _VECTOR(17)
#define SIG_2WIRE_SERIAL            _VECTOR(17)

/* Store Program Memory Ready */
#define SPM_RDY_vect                  _VECTOR(18)
#define SIG_SPM_READY                  _VECTOR(18)

INT0 and INT1 are external interrupts on the arduino pins 2 and 3 respectivily. they can be configured to react in different way's: trigger on rising or falling slope. LOW and change (like gonging from low to high or the other way round. these settings are controlled with a few bits in the MCUCR register:

two bits to set the interupt mode for each external interupt pin:

ISC01 ISC00 (int0)
ISC11 ISC10 (int1) interupt if:
0 0 low
0 1 change
1 0 falling slope
1 1 rising slope

void setup() {

MCUCR |= (1<<ISC01);
MCUCR |= (0<<ISC00);  // should set a falling slope for int0 = arduino pin 2 

...
}

this is done in the setup portion of your code.

comments appreciated.

Oh and btw, my sleep project is almost finished. you can follow it here:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166480143