Harmony v3 Peripheral Libraries on SAM E70/S70/V70/V71: Step 2

Step 2.1: Configure TC Peripheral Library

1

Under the bottom left Device Resources tab, expand Harmony > Peripherals > TC.
Double click or drag and drop TC0 to add the Timer Clock 0 (TC0) Peripheral Library (PLIB) to the project graph.

tc_adding.png

2

Set the TC0 to run at 1000 Hz low-speed clock.

When a module is added to the project graph, MPLAB® Code Configurator (MCC) automatically enables the clock to the module. The default TC0 clock source is 32000 Hz Slow Clock (SLCK).

tc_clock_setup.png

On the SAME70 device, TC0 can be clocked from various clock sources with frequencies ranging from 32 kHz to 300 MHz as shown above. TC0 can be sourced through a low-speed clock using the clock divisor. In the above screenshot, TC0 is sourced through a 1000 Hz low-speed clock source. The 1000 Hz low-speed clock is enough to generate periods at 500 milliseconds, 1 second, 2 seconds, and 4 seconds.

3

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

tc_configuration_setup.png

Make sure the Enable Period Interrupt is checked. This is because the timer needs to run in Periodic mode instead of One-Shot mode.

Step 2.2: Configure I²C Peripheral Library and I²C pins

1

Under the Device Resources tab, expand Harmony > Peripherals > TWIHS

Double click on Two-Wire Interfaces 0 (TWIHS0) to add the TWIHS instance 0 to the project.

twihs_selection.png

Select the TWIHS 0 PLIB and configure it for I²C protocol as shown.

twihs_setup.png

The TWIHS0 (I²C) retains the default 400 kHz speed because the temperature sensor chip on I/O1 Xplained Pro Extension Kit can operate at 400 kHz I²C speed.

2

Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration.

open_pin_configuration.png

3

Select the Plugins > Pin Settings tab and sort the entries by Ports names as shown below.

twihs_pins_setup_1.png

Now, select the Pin Table tab and then scroll down to the TWIHS0 module as shown below.

  • Enable I²C Clock (TWIHS0_TWCK0) on PA04 (Pin #77).
  • Enable I²C Data (TWIHS0_TWD0) on PA03 (Pin #91).
twihs_pins_setup_2.png

This completes the configuration of the I²C PLIB. 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 USART Peripheral Library and USART pins

1

Under the tab Device Resources tab, expand Harmony > Peripheral > USART.

Double click on USART1 to add the Universal Synchronous Asynchronous Receiver Transmitter (USART) instance 1 to the project.

usart_selection.png

Select the USART1 PLIB in the Project Graph and configure it for USART protocol, including setting the baud rate to 115200Hz.

usart_setup.png

2

Select the Pin Table tab and then scroll down to the USART1 module as shown below.

Enable USART_TX on PB04 (Pin #105).

usart_pins_setup.png

The application will use the USART PLIB for printing messages on the serial terminal. Hence, in the USART1 configuration, only the transmit functionality is enabled and the receive functionality is disabled.

Step 2.4: Configure DMA Peripheral Library

1

Launch DMA Configurator by going to the Project Graph tab in MPLAB X IDE and then selecting Plugins > DMA Configuration.

open_dma_configuration.png

2

Click on the DMA Settings tab. Configure Direct Memory Access (DMA) Channel 0 to transfer the application buffer to the USART TX register. The DMA transfers one byte from the user buffer to USART transmit buffer on each trigger.

Based on the trigger source, the DMA channel configuration is automatically set by MCC.

  • Source Address Mode, Destination Address Mode: Select whether to increment Source/Destination Address after every transfer. Automatically set by MCC based on the trigger type. For example:
    • If the trigger source is USART transmit, then the Source Address is incremented, and the Destination Address is fixed.
    • If the trigger source is USART receive, then the Source Address is fixed, and the Destination Address is incremented.
  • Data Width: Size of one transfer. The default value is 8-bits. For example:
    • If the Serial Peripheral Interface (SPI) is configured for 16-bit/32-bit mode, then the data width must be set to 16-bits/32-bits respectively.
  • Chunk Size: Some peripherals can hold more than one data as they have an internal FIFO. To optimize the data transfer, the chunk size can be set to match the internal FIFO size of the peripheral FIFO.
    • In the default configuration, the chunk size is set to 1 request (1 byte) per transfer.
  • Memory Burst Size: This is a very fast data transfer mode. It can perform up to 16 transfers (beats) before releasing the control of the system bus back to the CPU. The default value of burst length is one transfer.
    • In the default configuration, USART is configured for one-byte data at a time. So, the burst length is configured as one transfer.
usart_dma_setup.png



Next Step >

© 2024 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.