[Icc-avr] Interrupt Help Please (Happy New Year)

John Baraclough j_baraclough at zetnet.co.uk
Wed Jan 2 09:24:37 PST 2008


You need to initialise the interrupts correctly so that they respond to 
the appropriate edges.

I once solved a problem by putting a couple of NOPs after the sleep 
instruction and have always done it since. I still don't know why it 
worked but it's just routine now.

  asm("sleep");
  asm("nop");
  asm("nop");

HTH

John


Andrew wrote:
> Hi John,
>
> My main code is basically this: -
> //----------------------------------------------------------------------------- 
>
> // Sleep Function
> //----------------------------------------------------------------------------- 
>
>
>
> void sleep_mode(void)
> {
>
> DF_Deep_Power_Down();
> DF_Deep_Power_Down_2();
>
> SPCR = 0x00;
> ACSR |= 0x80;
>
> UCSRB = 0x00;
> PRR1 |= 0x08;
> REGCR |= 0x01;
>
> PORTD = 0x00;
>
> //port_init_off();
>
> SMCR = 0;
> SMCR = 5;
> asm("sleep");
> }
>
> //----------------------------------------------------------------------------- 
>
> // Main Program Loop
> //----------------------------------------------------------------------------- 
>
> void main(void)
> {
>
> init_devices();
>
> Usb_enable_regulator();
> usb_scheduler_init();
>
> sleep_mode();
>
> while (1)
> {
>
>
> if(!TestBit(bFlags,TEST_MODE))
> usb_scheduler_tasks();
>
> }
> }
>
> //----------------------------------------------------------------------------- 
>
> // INT0 - Interruopt Handler
> //----------------------------------------------------------------------------- 
>
> #pragma interrupt_handler int0_isr:iv_INT0
> void int0_isr(void)
> {
> //external interupt on INT0
> }
>
> What i need to do is if either INT0 or INT1 go from low to high i need 
> to wake the system from sleep and re-enable the USB and SPI, but i am 
> having problems.INT0 goes from low to high if a USB cable is pulgged 
> in and INT1 is high if the device switchs from a battery source to a 
> main power source. either of these need to resut in waking the system. 
> Then i put the system to sleep if INT1 is low and reset theinterrupts. 
> Andy help would be good.
>
> Thanks,
>
> Andy



More information about the Icc-avr mailing list