MPLAB® Harmony v3 Peripheral Libraries on SAM D21: Step 3

Last modified by Microchip on 2023/11/09 09:08

Configure Pins for Switch and LED

Configure Switch Button Pin with the External Interrupt Controller (EIC) to Generate an Interrupt
In this step, the switch button will be configured as per the below SW0 configuration in the SAM D21 Xplained Pro Evaluation Kit.

user button schematic

In MPLAB® Harmony Configurator (MHC), select the Pin Settings tab and then scroll down to the PORT pin PA15 (Pin Number 32) in the Pin ID column and configure PA15 as an external interrupt pin for switch functionality as shown in the accompanying image.

Internal pull-up is enabled to avoid false edge detection as there is no external pull-up on the SAM D21 Xplained Pro Evaluation Kit.

EIC pin configuration

Select the Project Graph tab.

Under the Available Components tab, expand Peripheral > EIC. Select and double click on EIC to add the EIC module to the project.

Peripheral > EIC menu

Configure the EIC block to generate an interrupt every time the user presses the switch SW0 as shown in the accompanying image, and enable filter functionality to avoid electrical noise on the switch pin.

Configuration Options pane

Back to Top


Configure LED Pin

In this step, the user LED will be configured as per the below LED0 configuration in the SAM D21 Xplained Pro Evaluation Kit.

user LED schematic

Select the MHC Pin Settings tab and then scroll down to the PORT pin PB30 (Pin Number 59) in the Pin ID column and configure PB30 as an output pin for LED functionality as shown in the accompanying image.

Pin Settings window

The LED on the SAM D21 Xplained Pro Evaluation Kit is active low. Configure the LED in default OFF state by configuring the latch value to logic "High".

Back to Top


Rename the Default Main File

Under the Project Graph tab, click on System, and configure as below to give the name of your liking to the default template main file generated by MHC.

main file name setup

The name of the default main.c is changed to main_d21.c to indicate that the referred main.c is for the SAM D21 getting started training module.

Back to Top