Low Power Application on SAM D21 Using Harmony v3 Peripheral Libraries: Step 2

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

Configure Real-Time Clock (RTC) Peripheral Library
Under the bottom left Available Components tab, expand Peripherals > RTC.

Double-click or drag and drop RTC to add the RTC Peripheral Library (PLIB) to the project graph.
Expanding Peripherals > RTC

In the Clock Easy View, open the Peripheral Clock Configuration window by clicking on the Peripheral Clock Configuration button.

Peripheral Clock Configuration windowOnce the window is opened, scroll down to the RTC peripheral and select GCLK1 (1 kHz) as the source clock to generate the peripheral clock frequency.
Scrolling down to the RTC peripheral and selecting GCLK1 (1 kHz) as the source clock

When a peripheral is added to the project, the peripheral clock is automatically fed by the GCLK0. However, you must configure the peripheral clocks according to your needs (power consumption, performance, etc.)

Go back to the project graph and configure the RTC PLIB to generate a compare interrupt every 500 milliseconds.

Generating a compare interrupt every 500 milliseconds

 The Compare Value is set as 0x200. This compare value generates an RTC compare interrupt every 500 milliseconds

  • RTC clock = 1024 Hz
  • RTC Prescaler = 1
  • Required Interrupt rate = 500 ms

Hence, Compare Value = (500/1000) x 1024 = 512 (i.e., 0x200).

Back to Top


Configure I²C Peripheral Library, I²C Pins, and Verify I²C Clock
Under the Available Components tab, expand Peripherals > SERCOM. Double-click on SERCOM2 to add the SERCOM instance 2 to the project.

Expanding Peripherals > SERCOMSelect the SERCOM 2 Peripheral Library and configure it for the I²C protocol.

Selecting the SERCOM 2 Peripheral Library 

  • SERCOM2 (as I²C) retains the default 100 kHz speed because the temperature sensor chip on the I/O1 Xplained Pro Extension Kit can operate at 100 kHz I²C speed.
  • SERCOM2 (as I²C) retains the default 50-100 nanoseconds hold time for Serial Data (SDA) Hold Time because it aligns with the minimum (50 nanoseconds) start to hold time in the specification of the temperature sensor chip (AT30TSE758).
  • SERCOM2 (as I²C) retains the default 100 nanoseconds for I²C Trise time because it aligns with the maximum (300 nanoseconds) input rise time in the specification of the temperature sensor chip (AT30TSE758).
Open the Pin Configuration tab by clicking MHC > Tools > Pin Configuration.

Opening the Pin Configuration tab

Select the MHC Pin Settings tab and sort the entries by Ports.

Selecting the MHC Pin Settings tab

Now, scroll down to the PA08 and PA09 pins as follows.

  • Enable I²C Clock (TWI_SCL)(SERCOM2_PAD1) on PA09 (Pin #18)
  • Enable I²C Data (TWI_SDA)(SERCOM2_PAD0) on PA08 (Pin #17)

Scrolling down to the PA08 and PA09 pins

In Clock Easy View, open the Peripheral Clock Configuration by clicking on the button Peripheral Clock Configuration.

Opening the Peripheral Clock ConfigurationOnce the window is opened, scroll down to the SERCOM2_CORE peripheral and verify GCLK0 (48 MHz) as the source clock to generate the peripheral clock frequency.

Scrolling down to the SERCOM2_CORE peripheral

This completes the configuration of the I²C peripheral library. The application code will use the I²C PLIB Application Programming Interfaces (APIs) to read the temperature from the temperature sensor. 

Back to Top


Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) Peripheral Library, USART Pins, and Verify USART Clock
Under the Available Components tab, expand Peripherals > SERCOM.

Double-click on SERCOM3 to add the SERCOM instance 3 to the project.

Expanding Peripherals > SERCOMAssociate the STDIO tool with SERCOM instance 3 (USART) peripheral by right-clicking on the yellow diamond.

Right-clicking on the yellow diamondRight-clicking on the yellow diamond

In Clock Easy View, open the Peripheral Clock Configuration by clicking on the Peripheral Clock Configuration button.

Opening the Peripheral Clock ConfigurationOnce the window is opened, scroll down to the SERCOM3_CORE peripheral and set GCLK2 (32 kHz) as the source clock to generate the peripheral clock frequency.

Scrolling down to the SERCOM3_CORE peripheral and setting GCLK2 (32 kHz) as the source clock

Note: The default main clock source will take time to settle once after wakeup from Standby Sleep mode. So, the USART clock source is changed to GLCK2, as GCLK2 sourcing from the XOSC32K oscillator and this XOSC32K will run even in Standby Sleep mode.

Select the SERCOM3 Peripheral Library in the Project Graph, verify the default SERCOM Operation Mode configuration is set as USART, and configure it.

Selecting the SERCOM3 Peripheral Library in the Project Graph The default Baud rate is set to 4800 Hz, as the peripheral is set at a low-frequency clock of 32 kHz.

Select the Pin Table tab and then scroll down to the SERCOM3 module as follows.
  • Enable USART_TX (SERCOM3_PAD0) on PA22 (Pin #43)
  • Enable USART_RX (SERCOM3_PAD1) on PA23 (Pin #44)

Selecting the Pin Table tab

Back to Top