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

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

Configure TC Peripheral Library

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

Available Components tab  

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

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

Program Clock Controller

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.

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

Configuration Options

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

Configure I²C Peripheral Library and I²C pins

 Under the Available Components tab, expand Peripherals > TWIHS

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

Available Components tab

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

Configuration Options

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.

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

Clicking MHC > Tools > Pin Configuration

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

Selecting the MHC Pin Settings tab

Now, select the MHC 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)

Selecting the MHC Pin Table tab

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.

Configure USART Peripheral Library and USART pins

 Under the tab Available Components tab, expand Peripheral > USART.

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

Available Components tab

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

Selecting the USART1 PLIB in the Project Graph

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

Enable USART_TX on PB04 (Pin #105).

Selecting the Pin Table tab

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

Configure DMA Peripheral Library

Launch DMA Configurator by going to the MHC tab in MPLAB X IDE and then select Tools > DMA Configuration.

Launching DMA Configurator

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

  • Source Address Mode, Destination Address Mode: Select whether to increment Source/Destination Address after every transfer. Automatically set by MHC 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.

DMA Settings

Disable USART interrupt

  • Under the Project Graph tab, click on the USART1 block.
  • In the Configuration Options, uncheck the Enable Interrupts option.

Configuration Options

In this lab, USART 1 interrupt is disabled as the application does not need a callback on USART transfer complete. A USART transmit buffer empty event triggers DMA to transfer one byte of data from source (user buffer) to destination (USART Tx register). When all the requested bytes are transmitted, DMA PLIB notifies the application by calling the registered DMA callback event handler.

Back to top