Electronic – Does anyone have any examples or suggestions utilizing Atmel’s ATMEGA2560 and external interrupt’s

atmegaatmelinterrupts

I am trying to utilize an ATMEGA2560 and it's interrupt. I have some code that must execute until a button is pressed at which time I need the code to stop and wait for another button press to continue.

Is anyone familiar with this type of circuit and the interrupts?

Here is what I am currently referencing for the ATMEGA2560 interrupts.

Best Answer

@ LoneTech: I figured this site was to help people. Not put them down for lack of information, but to provide it for them if the need is there. Also, Interrupts can be used to interrupt other code without hurting the speed of your main loop. If your button is supposed to change a process and your main loop is controlling a wave or something. INT0 could be used. You also don't know what other operations this individual plans on using it for.

@ Michael: This code took me a while to track down and understand as well. I have written code for AVRs for 5+ years now and for PC 13+ years. Its amazing how little documentation is there at your fingertips. I ran across a nice tutorial and finally it clicked.

void InitINT0()
{
    // Enable INT0 External Interrupt
    EIMSK |= 1<<INT0;

    // Falling-Edge Triggered INT0 - This will depend on if you
    // are using a pullup resistor or a pulldown resistor on your
    // button and port
    MCUCR |= 1<<ISC01;
}

int main(void)
{
    //Init Timer
    InitINT0();

    //Which Interrupt pin you need to enable
    //can be found in the datasheet, look at the pin
    //configuration, usually within the first 5 pages
    //track down INT0 - which is PORTD pin 0.
    //This needs to be an input.
    DDRD &= 0;

    // Enable Interrupts
    sei();

    //Givin that PORTD0 is the INT0, your button should
    //be hooked up to it.

    while(1)
    {
        //Do your operation
    }
}

// External Interrupt 0 ISR
ISR(INT0_vect) 
{
    while (/*Button is down*/) //0 is the pin for your button
    { 
        //Pause your operation , this will pause everything though
        //because Interrupts take priority over pretty much everything
        //This includes other interrupts and your main loop
    }
}