9.1 USART with Direct Pin Enable

Direct Mode is a mode in which peripherals are running based on function priority for pins and not using Peripheral Pin Selection(PPS).

Software

Hardware

1. WBZ451 Curiosity board

Developing an Application from Scratch using MPLAB Code Configurator

This section explains the steps required by a user to develop an application example from scratch using MPLABx Code Configurator.
Note: New users of MPLAB Code Configurator are recommended to go through the overview.
  1. Create a new MCC Harmony Project. For more instructions, refer toCreating a New MCC Harmony Project for instructions

  2. User can find Device Resources window right below the Project resource tab

Figure 9-2. Device Resources.

1. Add SERCOM0 from Peripherals list.

Figure 9-3. SERCOM0 Peripheral.

2. Project graph view after adding SERCOM0 to the project resources.

Figure 9-4. Project Graph.

Verify UART Configuration

1. Select SERCOM0 component in project graph. SERCOM0 USART provides 3 operating modes:

a ) Ring buffer mode

In ring buffer mode, the receiver is always enabled, and the received data is saved in the internal receive ring buffer, size of which can be configured using MHC. The application can use the API calls to read the data out from the ring buffer. APIs are provided to query the number of (unread) bytes available in the receive buffer, free space in the receive buffer and size of the receive buffer. Similarly, during transmission, the application data is deep copied into the internal transmit ring buffer, size of which can be configured using MHC. This allows the use of local buffers for data transmission. APIs are provided to query the free space in the transmit buffer, number of bytes pending transmission and the size of the transmit buffer. Additionally, application can enable notifications to get notified when n bytes are available in the receive buffer or when n bytes of free space is available in the transmit buffer. The APIs allow application to set the threshold levels for notification in both receive and transmit buffers. Further, application can also choose to enable persistent notifications, whereby the application is notified until the threshold condition is met.

Figure 9-5. Ring buffer mode configuration options.

b) Blocking mode

In blocking mode, the transfer APIs block until the requested data is transferred.

Figure 9-6. Blocking mode configuration options.

c) Non-blocking mode

In non-blocking mode the peripheral interrupt is enabled. The transfer API initiates the transfer and returns immediately. The transfer is then completed from the peripheral interrupt. Application can either use a callback to get notified when the transfer is complete or can use the IsBusy API to check the completion status.

Figure 9-7. Non-blocking mode configuration options.

2. Select system component in project graph and set SERCOM0 in "Direct" mode.

Figure 9-8. System configuration.

Generating a Code

For instructions, refer to MPLAB Code Configurator(MCC) Code Generation

The sercom initialization routine executed during program initialization can be found in the project files. This initialization routine is automatically generated by the MCC according to the user settings.

Header Files

Header File associated with sercom0 peripheral library or any other peripheral library for a different example is included in definitions.h file.

Function Calls

MCC generates and adds the code to initialize the UART peripheral in SYS_Initialize() function.

SERCOM0_USART_Initialize() is the API that will be called inside the SYS_Initialize() function.

User can exercise SERCOM0_USART_Write() api to create a “Hello World” application example like this:

Figure 9-9. App example

Testing

Connect the WBZ451 Curiosity board to PC, program the application example. Open TeraTerm(Speed: 115200, Data: 8-bit, Parity: none, stop bits: 1 bit, Flow control: none) and select the COM port that is enumerated when connecting the WBZ451 Curiosity Board. Reset the board and your application example will output the message in Tera term

Figure 9-10. Terminal window