5.8 Supporting Interrupts for AVR® Devices

This section demonstrates how to enable interrupts in the bootloader and application code for AVR® devices.

Description: It is always recommended to avoid using interrupts in the bootloader code, when possible, to avoid errors due to complexity, but user applications can freely support interrupts. Enabling interrupts for AVR devices in the application space is as simple as setting up the interrupt sources and creating the desired functionality. There are no additional steps required within the bootloader project in order to achieve basic interrupt support in the application space. The following section will walk through the setup of an application that is blinking the LED using a timer interrupt instead of using the delay driver.

Note: The projects used in this example can be created by following the Creating a Bootloader Client for AVR® Devices and the Creating an Application for AVR® Devices sections of this document.
To support interrupts in the bootloader code, there are a few changes needed in the interrupt manager. These changes are only needed if you would like to use interrupts in the bootloader code.
  1. Set the bootloader project as the main project. From the Projects tab, right click on the project folder and select Set as Main Project.
    Figure 5-178 5-181. Set the Bootloader to the Main Project
  2. Open MCC by clicking the icon in the toolbar.
    Figure 5-179 5-182. Open MCC
  3. Open the Interrupt Manager tab and enable the sliders for Global Interrupt Enable and Interrupt Vector Select Enable.
    Figure 5-180. Set the Bootloader Interrupt Manager
  1. Set the application project as the main project. From the Projects tab, right click on the project folder and select Set as Main Project.
    Figure 5-178 5-181. Set the Application as the Main Project
  2. Open MCC by clicking the icon in the toolbar.
    Figure 5-179 5-182. Open MCC
  3. Navigate to the Project Resources tab, and click the red x-box next to the Delay module.
    Figure 5-183. Remove the Delay driver
  4. Navigate to the Device Resources tab and add the TCA0 driver.
    Figure 5-184. Add TCA0
    1. Setup the TCA0 driver to use a time-out of 150 ms or more and then enable the Overflow Interrupt.
      Figure 5-185. Configure the TCA0 Module
  5. Notice that once the Overflow Interrupt is enabled, there is a notification for enabling global interrupts. Navigate to the Interrupt Manager tab and flip the switch for Global Interrupt Enable.
    Figure 5-186. Enable Global Interrupts
  6. Generate the new timer code and observe the new files being generated in the Output window.
    Figure 5-187. Regenerate the MCC Code
  7. Lastly, update the main.c to blink the LED using the overflow interrupt callback. Remove the calls to the Delay driver and update the main.c similar to the example below.
    Figure 5-188. Update the Blinking LED Code to Use Interrupts