You are on page 1of 4

Arduino (http://arduino.

cc)
Search the Arduino Forum
search

Advanced Search (http://forum.arduino.cc/index.php?action=search;advanced) (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&) | Arduino Forum (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&) :: Using Arduino (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&#2) :: Programming Questions (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&board=4.0) :: Pure AVR equivalent of attachInterrupt() ? previous topic (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.0;prev_next=prev#new) next topic (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.0;prev_next=next#new)
Reply (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=post;topic=107765.0;num_replies=6) Notify (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=notify;sa=on;topic=107765.0;sesc=fcac0051a502c81941130a2074358202) Send this topic (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=sendtopic;topic=107765.0)

Pages: [1] Go Down

Print (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=printpage;topic=107765.0)

Author Topic: Pure AVR equivalent of attachInterrupt() ? (Read 506 times) 0 Members and 1 Guest are viewing this topic.

magagna (http://forum.arduino.cc//index.php? Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index.php PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809181#m PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809181#msg809181) on: May 29, 2012, 01:12:09 am Southern California Offline God Member Karma: 5 Posts: 532 I like blinky lights I'd like to add a "system halt" button to my mill running GRBL. The button is on D2, hardware interrupt 0. In Arduino-speak I can set it up with attachInterrupt(0...) but for GRBL I need a pure AVR C implementation. Before I start trying to pull apart the source code in WInterrupts.c etc. I was wondering if anyone's already done this or has a reference to an example.

(http://forum.arduino.cc//index.php? Thanks in advance. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://bubbletronics.com) http://en.wiktionary.org/wiki/magagna (http://en.wiktionary.org/wiki/magagna) <-- My last name. Pretty apt.

Logged

Coding Badly (http://forum.arduino.cc//index.php? Re: Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=10859) (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809184#m PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809184#msg809184) Reply #1 on: May 29, 2012, 01:19:29 am Global Moderator Dallas Offline Shannon Member Karma: 147 Posts: 11022 Processor? Trigger (CHANGE, RISING, FALLING, LEVEL)?

(http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=10859) (http://code.google.com/p/arduinotiny/) Logged

magagna (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://forum.arduino.cc//index.php?

Re: Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809187#m

PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809187#msg809187) Reply #2 on: May 29, 2012, 01:21:34 am Southern California Offline God Member Karma: 5 Posts: 532 I like blinky lights I apologize. I'm using a Uno with a 328P and would like the trigger to be on RISING. Thanks! Logged

(http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) http://en.wiktionary.org/wiki/magagna (http://en.wiktionary.org/wiki/magagna) <-- My last name. Pretty apt. (http://bubbletronics.com)

Coding Badly (http://forum.arduino.cc//index.php? Re: Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=10859) (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809191#m PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809191#msg809191) Reply #3 on: May 29, 2012, 01:30:32 am Global Moderator Dallas Offline Shannon Member Karma: 147 Posts: 11022 For INT0 on the 328 processor, we end up at the interrupt service routine on line #276... https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WInterrupts.c#L276 (https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WInterrupts.c#L276)

(http://forum.arduino.cc//index.php? We'll use the modern macro instead of the deprecated SIGNAL macro... PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=10859) Code: (http://code.google.com/p/arduinoISR( INT0_vect ) tiny/) { // Your stuff goes here } The EICRB register does not exist does we end up with this initialization code on line #95... https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WInterrupts.c#L95 (https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WInterrupts.c#L95) Code: EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); EIMSK |= (1 << INT0); RISING is defined as 3... https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/Arduino.h#L40 (https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/Arduino.h#L40) ...so the initialization code becomes this... Code: EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (3 << ISC00); EIMSK |= (1 << INT0); And, we're done. Logged

magagna (http://forum.arduino.cc//index.php? Re: Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809193#m PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg809193#msg809193) Reply #4 on: May 29, 2012, 01:33:42 am Southern California Offline God Member Karma: 5 Posts: 532 I like blinky lights That's great, thanks! I won't be able to test it out until tomorrow evening but I'll let you know how it goes. Thanks again. Logged

(http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://bubbletronics.com) http://en.wiktionary.org/wiki/magagna (http://en.wiktionary.org/wiki/magagna) <-- My last name. Pretty apt.

magagna (http://forum.arduino.cc//index.php? Re: Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg810095#m PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg810095#msg810095) Reply #5 on: May 29, 2012, 09:28:24 pm Southern California Offline God Member Karma: 5 Posts: 532 I like blinky lights It compiled fine but didn't function until I added Code: #include <avr/interrupt.h>

(http://forum.arduino.cc//index.php? Once I did that it worked as designed. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=18240) (http://bubbletronics.com) Thanks again for your help. Logged http://en.wiktionary.org/wiki/magagna (http://en.wiktionary.org/wiki/magagna) <-- My last name. Pretty apt.

Coding Badly (http://forum.arduino.cc//index.php? Re: Pure AVR equivalent of attachInterrupt() ? (http://forum.arduino.cc//index. PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=10859) (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg810100#m PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.msg810100#msg810100) Reply #6 on: May 29, 2012, 09:53:10 pm Global Moderator Dallas Offline Shannon Member Karma: 147 Posts: 11022 Excellent. I'm glad you have it working.

(http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=profile;u=10859) (http://code.google.com/p/arduinotiny/) Logged

Reply (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=post;topic=107765.0;num_replies=6) Notify (http://forum.arduino.cc//index.php?

Pages: PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=notify;sa=on;topic=107765.0;sesc=fcac0051a502c81941130a2074358202) [1] Go Send this topic (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=sendtopic;topic=107765.0) Up


Print (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=printpage;topic=107765.0)

previous topic (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.0;prev_next=prev#new) next topic (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&topic=107765.0;prev_next=next#new) (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&) | Arduino Forum (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&) :: Using Arduino (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&#2) :: Programming Questions (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&board=4.0) :: Pure AVR equivalent of attachInterrupt() ?
Move Topic (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=movetopic;topic=107765.0) Remove Topic (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=removetopic2;topic=107765.0;sesc=fcac0051a502c81941130a2074358202) Lock topic (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=lock;topic=107765.0;sesc=fcac0051a502c81941130a2074358202)

Set topic sticky (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=sticky;topic=107765.0;sesc=fcac0051a502c81941130a2074358202) Merge Topics (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=mergetopics;board=4.0;from=107765) Remove Poll (http://forum.arduino.cc//index.php?PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=removepoll;topic=107765.0) Link to Calendar (http://forum.arduino.cc//index.php? PHPSESSID=47gdirkrsvmqg97pr5l1bgg4q0&action=post;calendar;msg=809181;topic=107765.0;sesc=fcac0051a502c81941130a2074358202)

Jump to:
=> Programming Questions go

2011 Arduino Forum: Powered by SMF 1.1.18 (http://www.simplemachines.org/) | SMF 2013, Simple Machines (http://www.simplemachines.org/about/copyright.php)