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

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

Build, Program, and Observe the Outputs

Verify that the temperature sensor (I/O1 Xplained Pro Extension Kit) is connected to Extension Header 1 (EXT1) on the SAM D21 Xplained Pro Evaluation Kit.

connected to Extension Header 1

The SAM D21 Xplained Pro Evaluation Kit allows the Embedded Debugger (EDBG) to be used for debugging.


Connect the Type-A male to micro-B USB cable to the micro-B DEBUG USB port to power and debug the SAM D21 Xplained Pro Evaluation Kit.

connected to PC

Back to Top


In MPLAB® X IDE, go to File > Project Properties and make sure that the EDBG is selected as the debugger under the Hardware Tools and XC32 (v2.20) is selected as the Compiler Toolchain for XC32.

Project Properties window

Back to Top


Clean and build your application by clicking on the Clean and Build button as shown in the accompanying image.

Clean and Build button

Back to Top


Program your application to the device by clicking on the Make and Program button as shown in the accompanying image.

Make and Program button

The lab should build and program successfully.

Back to Top


Now, open the Tera Term terminal application on your PC (from the Windows® Start menu by pressing the Start button). Select the Serial Port as shown in the accompanying image.

tera term new connection window

Back to Top


Change the baud rate to 115200.

Setup > Serial port menu

baud rate setup

Back to Top


You should see the temperature values (in °F) being displayed on the terminal every 500 milliseconds, as shown in the accompanying image.

temperature values

Also, notice the LED0 blinking at a 500 millisecond rate.

Back to Top


You may vary the temperature by placing your finger on the temperature sensor (for a few seconds).

temperature sensor

Back to Top


Press the SW0 switch on the SAM D21 Xplained Pro Evaluation Kit to change the default sampling rate to one second.

SW0 switch

Sampling every 1 second

Back to Top


Every subsequent pressing of the SW0 switch on the SAM D21 Xplained Pro Evaluation Kit changes the default sampling rate to 2 seconds, 4 seconds, 500 milliseconds, and back to 1 second in cyclic order as shown in the accompanying image.

change Temp Sampling Rate

While the temperature sampling rate changes on every switch SW0 press, notice the LED0 toggling at the same sampling rate.

Back to Top

Results

You observed that the application displayed the current room temperature values on the serial terminal every 500 milliseconds. You were able to change the temperature sampling values dynamically by pressing a user switch on the development kit. You could exercise sampling changes to one second, two seconds, or four seconds, and cycle back to 500 milliseconds every time you pressed the user switch. You also observed that a user LED was toggled every time the current temperature is displayed on the serial terminal.

Back to Top

Analysis

You have successfully created your first application using MPLAB Harmony v3 on a SAM D21 microcontroller. Your application used all the fundamental elements that go into building a real-time application. Your application successfully read temperature sensor values and displayed them periodically over a serial terminal on a PC. The application also took user input by pressing a switch on the development board.

In this application, you used MPLAB Harmony Configurator (MHC) to configure the SAM D21 and also used the MPLAB Harmony v3 Framework. You used the clock configurator to set up the CPU clock and timer (Real-Time Clock (RTC)) clock. You configured SERCOM 2 (as I²C), SERCOM 3 (as Universal Synchronous Asynchronous Receiver Transmitter (USART)), RTC, and External Interrupt Controller (EIC) Peripheral Libraries (PLIBs). You also configured the Direct Memory Access (DMA) using the DMA configurator. You used the pin configurator to set up the pins for LED and switch functions.

Back to Top

Conclusions

This tutorial provided you with training in configuring and using all the fundamental components needed to build a real-time application on a SAM D21 microcontroller with MPLAB Harmony v3 Framework. As a next step, you may customize this application and reconfigure some of the components used in this tutorial. You could also add new components (PLIBs, etc.) to enhance this application to realize your end application.

Back to Top