[Icc-avr] Interrupt Help Please (Happy New Year)
John Baraclough
j_baraclough at zetnet.co.uk
Wed Jan 2 09:10:02 PST 2008
Andrew wrote:
> Hi John,
>
> Thansk for the explanation, quick question i am using the following to
> turn the AT90USB162 into the lowest power sleep mode: -
>
> SPCR = 0x00;
> ACSR |= 0x80;
>
> UCSRB = 0x00;
> PRR1 |= 0x08;
> REGCR |= 0x01;
>
> port_init_off();
>
> SMCR = 0;
> SMCR = 5;
> asm("sleep");
>
That all looks fine, but for improved readability and portability try to
use the bit names
SMCR = BIT(SM1) | BIT(SE);
You must include <macros.h> for this to work.
>
>
> Is there anything else i am missing?
>
> Quick Question regarding sleep mode - when the device is in sleep mode
> is there anyhting else that can wake-up the AVR apart from an
> interrupt? also how do i set the interrupt for INT1?
>
Yes, read section 8.2 on page 42 of the data sheet to see what other
sources there are and disable them accordingly.
> I think i write the folowing register to the following : -
>
> EIMSK |= 0x02;
>
Assuming you only want INT1 to be active, you would be better to write:
EIMSK = BIT(INT1);
EICRA = BIT(ISC11) | BIT(ISC10); // Set INT1 to rising edge.
> and then in the main code how do i write the C interrupt handler call
> code? for example when i use the application builder to set up a timer
> for example it produces the following code: -
>
> #pragma interrupt_handler timer1_ovf_isr:19
> void timer1_ovf_isr(void)
> {
>
> }
>
Try not to use absolute numbers for interrupt references, but use the
predefined macros. The names of these can be found in <ioUSB162v.h>.
#pragma interrupt_handler external_int_1:iv_EXT_INT1
void external_int_1(void)
{
SET_EXTERNAL_INT_FLAG;
EICRA = BIT(ISC11); // Set INT1 to fallng edge.
}
and in your main loop
if(TEST_EXTERNAL_INT_FLAG)
{
DoSleepStuffHere();
}
> But as there is no application builder for the AT90USB162 as yet how
> would i wite the above for a pin interrupt on INT1. Note Sorry i know
> there is information in the datasheet but as i am new to the world of
> AVR's i was just wondering if somebody could help me on this.
>
>
>
> Thansk Andy
More information about the Icc-avr
mailing list