Interrupts: Programming

Configuring interrupts is a process aided by DriverLib functions and macros, but the process itself is not a straightforward one. Since there are so many interrupt sources, each with its own specific interrupt handler, you will need to do some research in order to figure out what you will be looking for. The process can be broken down into a simple set of instructions, though:

Part 1: Hardware initialization

Part 2: Global variable setup

Part 3: Writing the ISR

Part 4: Writing the rest of the code

Before you read the rest of this page, it is best that you import the following repository:

https://github.com/ECE2564-VT/basic_example_interrupts.git 

Part1: HARDWARE Initialization

This part has two major steps on its own.

Init_A: Configuring the interrupt source

For this, we need to talk to the interrupt source (the peripherals such as GPIO, UART, I2C, etc.). It consists of several possible steps. 

This is peripheral-specific. Examples of functions that clear interrupt flags:

extern void Timer32_clearInterruptFlag(uint32_t timer);

extern void GPIO_clearInterruptFlag(uint_fast8_t selectedPort,

        uint_fast16_t selectedPins);

extern void UART_clearInterruptFlag(uint32_t moduleInstance, uint_fast8_t mask);


         Some interrupts are cleared by a specific action. Refer to each peripheral to see how interrupts are cleared. 

 



For all these steps, you need to look at the MSP432 user manual chapter associated with the interrupt source, e.g. GPIO, or the Driverlib header file for that component, e.g. io.h, or the Driverlib manual for that component.

Init_B: Configure the interrupt controller

For this, We need to talk to NVIC (Nested-Vector Interrupt Controller). We should enable the interrupt in the interrupt controller and possibly set the priorities.

 


For the above steps, you need to look at the MSP432 user manual chapter associated with NVIC or the Driverlib header file for interrupt.h, or the Driverlib manual for that NVIC (chapter 12).

The below two figures show the initialization for one button (digital i/o) and one Timer32. The steps associated with interrupt initialization are marked.

PART2:  Declare the communication variables


We need to declare the variables that can be used as means of communication between ISR and the rest of the functions.


The below screenshot shows these steps for the basic example mentioned earlier on this page. 


PART 3: writing the ISR

To start, we find the name of the interrupt trigger that ISR we need.  In CCS, there is a subdirectory called ccs within each project which contains a file startup_msp432p401r_ccs.c. That file contains a default interrupt vector table. The below figure shows a snippet of that file. As you can see some peripherals such as ADC14 (the A/D) has only one ISR while some such as Timer32 have more than one. 

ISR_A: Body of the ISR

 

ISR_B: Clearing the interrupt 


The below screenshot shows the ISR for port 1 that checks a button, S1.

part 4: writing the rest of the code

Finally, we write the body of the code for other functions.