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

Step 2.1: Configure Real-Time Clock (RTC) Peripheral Library

1

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.

rtc_adding.png

2

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

peripheral_clock_config.png

Once 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.

rtc_clock_configuration.png

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.)

3

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

rtc_configuration_setup.png

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).

Step 2.2: Configure I²C Peripheral Library, I²C Pins, and Verify I²C Clock

1

Under the Available Components tab, expand Peripherals > SERCOM.

Double click on SERCOM2 to add the SERCOM instance 2 to the project.

sercom_selection.png

Select the SERCOM 2 Peripheral Library and configure it for the I²C protocol.

sercom_setup.png
  • 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 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).

2

Open the Pin Configuration tab by clicking MHC > Tools > Pin Configuration.

open_pin_configuration.png

3

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

sercom_pins_setup_1.png

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)
sercom_pins_setup_2.png

4

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

peripheral_clock_config.png

Once 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.

sercom_2_clock_configuration.png

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.

Step 2.3: Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) Peripheral Library, USART Pins, and Verify USART Clock

1

Under the Available Components tab, expand Peripherals > SERCOM.

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

sercom_selection_for_uart.png

Associate STDIO tool with SERCOM instance 3 (USART) peripheral by right-clicking on the yellow diamond.

stdio_selection.png
stdio_linked.png

2

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

peripheral_clock_config.png

Once 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.

sercom_3_clock_configuration.png

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 XOSC32K oscillator and this XOSC32K will run even in Standby Sleep mode.

3

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

uart_sercom_setup.png

The default Baud rate is set to 4800 Hz, as the peripheral is set at a low-frequency clock of 32 kHz.

4

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)
uart_sercom_pins_setup.png



Next Step >

© 2022 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.