Bad Interrupt

If during the running of your program, an unexpected interrupt were to occur (an interrupt for which no handler is installed) bad things could occur. Default behavior is for the program to jump through the reset interrupt vector and attempt to restart your program. Best case is your program simply starts over.

But maybe this isn’t what you want to happen. Certainly for a critical microcontroller application (think medical device here), this might not be the best course of action. The program could get stuck in an endless error loop. If your device is a heart defibrillator, that could mean repeated shocking of the patient.


So, for the sake of writing robust code, we should plan and implement for this circumstance. This default behavior can be overridden by supplying a function named BADISR_vect defined as an ISR().


#include <avr/interrupt.h>

ISR(BADISR_vect)  {
  //flash warning lamp
  //set flag
  Bad_Interrupt_Occured = true;

The catch-all interrupt vector is described in the documentation here.

Empty Interrupt

Having covered the BAD INTERRUPT vector, we now must briefly cover the EMPTY INTERRUPT vector. With the BADISR_vect set to execute our specific code, we may still want some of they undefined interrupts to trigger a reset. We can accommodate this functionality through the use of the EMPTY_INTERRUPT macro:


Note: there is no body to this macro.

An example for this could be the case for interrupts that are enabled for the purpose of getting the controller out of sleep_mode().

About Jim Eli

µC experimenter
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s