You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-21Lines changed: 29 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
</a>
10
10
11
11
# Getting Started with SERCOM (UART) Communication on PIC32CM M0+ Devices
12
-
This example project demonstrates basic UART communication using the SERCOM peripheral on a PIC32CM JH00 device. The application transmits the message “Hello World” once every 500 ms using the SysTick timer, and the output can be viewed on a serial terminal connected to the board. This project provides a straightforward introduction to initializing SERCOM for UART operation and sending periodic messages.
12
+
This example project demonstrates basic UART communication using the SERCOM peripheral on a PIC32CM JH00 device. The application transmits the message “Hello World” once every 500 ms using the SysTick timer, and the output can be viewed on a serial terminal connected to the board. This project provides a straightforward introduction to initializing the SERCOM for UART operation and sending periodic messages.
13
13
14
14
While this project uses a PIC32CM JH00 device, the same initialization and communication principles apply to other PIC32CM M0+ devices.
15
15
@@ -34,8 +34,10 @@ While this project uses a PIC32CM JH00 device, the same initialization and commu
34
34
-[MPLAB® XC32 4.60 or newer](https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers/xc32)
This example project was developed in MPLAB X IDE and can also be opened in VS Code using the [MPLAB Extension Pack](https://marketplace.visualstudio.com/items?itemName=Microchip.mplab-extension-pack). Follow the provided instructions [here](https://developerhelp.microchip.com/xwiki/bin/view/software-tools/ides/extensions/get-started/importing-mplab-x-project-vs-code/) to import and run the project in VS Code.
37
+
## Opening Projects in Visual Studio Code (VS Code®)
38
+
This example project was developed in MPLAB X IDE and can also be opened in VS Code® using the [MPLAB Extension Pack](https://marketplace.visualstudio.com/items?itemName=Microchip.mplab-extension-pack). Follow the provided instructions [here](https://developerhelp.microchip.com/xwiki/bin/view/software-tools/ides/extensions/get-started/importing-mplab-x-project-vs-code/) to import and run the project in VS Code®.
39
+
40
+
For a step-by-step walkthrough on importing the project, watch the video: [Importing an MPLAB® X Project into Microsoft® VS Code®](https://www.youtube.com/watch?v=cf1bK6aLdlo)
UART communication is based on a simple point-to-point connection between two devices. One device’s TX (transmit) pin connects to the other device’s RX (receive) pin, and vice versa. This crossover allows data to flow in both directions, as shown in the diagram below.
61
+
UART communication is based on a simple point-to-point connection between two devices. One device’s TX (transmit) pin connects to the other device’s RX (receive) pin, and vice versa. This crossover allows data to flow in both directions, as shown in the following figure.
60
62
61
-
In this configuration, UART provides a straightforward way to exchange data without the need for a clock signal. For communication to work correctly, both devices must be configured with the same parameters:
63
+
In this configuration, the UART provides a straightforward way to exchange data without the need for a clock signal. For communication to work correctly, both devices must be configured with the same parameters:
62
64
63
-
- Baud Rate – Defines the speed of communication in bits per second. If the baud rates don’t match, the timing of bits will drift and data will be corrupted.
65
+
- Baud Rate – Defines the speed of communication in bits per second. If the baud rates do not match, the timing of bits will drift and data will be corrupted.
64
66
- Data Bits – Specifies how many bits represent the actual data (commonly 8). Both devices must agree to properly interpret each frame.
65
67
- Parity – An optional error-checking bit (None, Even, or Odd). If enabled, both sides must use the same setting to validate data integrity.
66
68
- Stop Bits – Mark the end of each data frame (typically 1 or 2). Mismatched stop bits cause framing errors.
67
69
68
-
Together, these settings ensure that transmitted bits are correctly packaged, sent, and interpreted on the receiving side, ensuring that transmitted bits are correctly interpreted on the receiving side.
70
+
Together, these settings ensure that the transmitted bits are correctly packaged, sent, and interpreted on the receiving side.
In this example, the concept is applied using the SERCOM1 peripheral configured as a UART. The onboard debugger uses a Communications Device Class (CDC) interface that appears on the host computer as a virtual COM port, allowing data to stream in both directions between the host and the target device.
78
+
In this example, the concept is applied using the SERCOM1 peripheral configured as a UART. The onboard debugger uses a Communications Device Class (CDC) interface that appears on the host computer as a virtual COM port, allowing the data to stream in both directions between the host and the target device.
77
79
78
-
Characters sent from the host are transmitted on the debugger’s CDC TX pin, while characters received on the CDC RX pin are returned to the host. The UART output can be viewed in a terminal program such as MPLAB Data Visualizer, making it easy to monitor or interact with the application over USB without extra hardware.
80
+
Characters sent from the host are transmitted on the debugger’s CDC TX pin, while characters received on the CDC RX pin are returned to the host. The UART output can be viewed in a terminal program such as the MPLAB Data Visualizer, making it easy to monitor or interact with the application over a USB without extra hardware.
@@ -123,7 +125,7 @@ Once programmed, the device continuously sends the `Hello World` message, which
123
125
<br>
124
126
125
127
### View the results:
126
-
To view the output of this project, launch MPLAB Data Visualizer from the MPLAB X IDE toolbar. In Data Visualizer, select the serial COM port associated with the PIC32CM JH00 Curiosity Nano and confirm that the settings match the configured SERCOM UART parameters in the Project Configuraiton section.
128
+
To view the output of this project, launch the MPLAB Data Visualizer from the MPLAB X IDE toolbar. In the Data Visualizer, select the serial COM port associated with the PIC32CM JH00 Curiosity Nano and confirm that the settings match the configured SERCOM UART parameters in the Project Configuration section.
@@ -140,7 +142,7 @@ The UART pins can be probed with a logic analyzer, where the output should decod
140
142
141
143
<!-- Provide instructions for configuring the project, including modifying parameters, setting up configuration files, and tuning options when necessary. -->
142
144
143
-
This example project is already provided as a preconfigured MPLAB X project. Start by opening the project in MPLAB X IDE. Once the project is loaded, launch MPLAB® Code Configurator (MCC) Harmony to review the configuration.
145
+
This example project is already provided as a preconfigured MPLAB X project. Start by opening the project in MPLAB X IDE. Once the project is loaded, launch the MPLAB® Code Configurator (MCC) in Harmony to review the configuration.
144
146
145
147
For detailed instructions on how to create and set up a new MPLAB X project and open MCC Harmony, refer to the this Microchip online reference [here](https://mplab-discover.microchip.com/v2/item/com.microchip.documentation/com.microchip.portal.webhelp/com.microchip.subcategories.tools.development-boards/tool-chain-guide.guid-45e21205-663c-4792-b2c1-e147f4c3ff92.html%23guid-45e21205-663c-4792-b2c1-e147f4c3ff92/1.0.0?view=about&dsl=3+AND+Tool+AND+Chain+AND+Guide)
146
148
@@ -171,7 +173,7 @@ To check the system clock, go to Project Graph → Plugins → Clock Configurato
171
173
172
174
### Step 2: Configuring the System Tick (SysTick)
173
175
174
-
SysTick is a built-in timer that allows the application to create precise delays without relying on software loops. In this demo, it will be used to add a fixed delay between each `Hello World` message sent over UART.
176
+
The SysTick is a built-in timer that allows the application to create precise delays without relying on software loops. In this demonstration, it will be used to add a fixed delay between each Hello World message sent over the UART.
175
177
176
178
To enable SysTick:
177
179
@@ -180,14 +182,14 @@ To enable SysTick:
180
182
181
183
<br>
182
184
183
-
2. In the Configuration Options panel, expand Cortex M0+ Configuration and Enable the SysTick option
185
+
2. In the Configuration Options panel, expand Cortex M0+ Configuration and enable the SysTick option.
### Step 3: Add and Configure the UART Peripheral (SERCOM1)
189
191
190
-
The device includes multiple SERCOM peripherals that can be configured as UART, SPI, or I²C. On the Curiosity Nano, only SERCOM1 is internally routed to the onboard debugger’s CDC interface, so it must be used for sending UART data to a terminal over USB.
192
+
The device includes multiple SERCOM peripherals that can be configured as UART, SPI, or I²C. On the Curiosity Nano, only SERCOM1 is internally routed to the onboard debugger’s CDC interface, so it must be used for sending the UART data to a terminal over a USB.
191
193
192
194
This information is available in the Pinout section of the [Curiosity Nano User's Guide](https://ww1.microchip.com/downloads/aemDocuments/documents/MCU32/ProductDocuments/UserGuides/PIC32CM-JH-Value-Line-Curiosity-Nano%2B-Touch-Evaluation-+Kit-User%E2%80%99s-Guide-DS70005600.pdf).
193
195
@@ -239,16 +241,17 @@ To assign the pins:
239
241
240
242
<br>
241
243
242
-
### Step 5: Generate MCC Code
243
-
With UART and SysTick configured, the final step is to generate code. MCC creates the initialization files, peripheral drivers, and APIs for UART communication and SysTick timing, preparing the project for application development.
244
+
### Step 5: Generate the MCC Code
245
+
With the UART and SysTick configured, the final step is to generate the code. The MCC creates the initialization files, peripheral drivers, and APIs for UART communication and SysTick timing, preparing the project for application development.
<!-- Describe the main source code structure, including key functions or files, and explain how the application logic works. -->
250
252
251
-
This code defines a macro for `"Hello World"`, starts the SysTick timer, and enters a loop that sends the `Hello_World` message over UART using `SERCOM1_USART_Write()`. Timing is provided by `SYSTICK_DelayMs()` to create a 500 ms delay and prevent flooding the terminal.
253
+
254
+
This code defines a macro for `"Hello World"`, starts the SysTick timer, and enters a loop that sends the `"Hello_World"` message over the UART using `SERCOM1_USART_Write()`. Timing is provided by `SYSTICK_DelayMs()` to create a 500 ms delay and prevent flooding the terminal.
252
255
253
256
<br>
254
257
@@ -283,8 +286,13 @@ int main(void)
283
286
<br>
284
287
285
288
## Conclusion
286
-
This project showed how to configure SERCOM in UART mode on a PIC32CM M0+ device using MCC Harmony. The system clock, SysTick timer, and SERCOM1 peripheral were set up to send a `"Hello World"` message every 500 ms over the Curiosity Nano’s USB CDC interface. This simple example provides a foundation for expanding into bidirectional communication or more advanced embedded applications.
289
+
This project showed how to configure the SERCOM in UART mode on a PIC32CM M0+ device using MCC Harmony. The system clock, SysTick timer, and SERCOM1 peripheral were set up to send a `"Hello World"` message every 500 ms over the Curiosity Nano’s USB CDC interface. This simple example provides a foundation for expanding into bidirectional communication or more advanced embedded applications.
287
290
288
291
289
292
## Related Projects
290
-
<!-- Add links, descriptions or any details of related projects of this example, if any -->
293
+
294
+
- [Getting Started with Blink LED on PIC32CM M0+ Devices](https://github.com/microchip-pic-avr-examples/pic32cmjh-blink-led-mplab-harmony)
295
+
- [Getting Started with Analog-to-Digital Converters (ADC) on PIC32CM M0+ Devices](https://github.com/microchip-pic-avr-examples/pic32cmjh-basic-adc-mplab-harmony)
296
+
- [Getting Started with QTouch® Button and Peripheral Touch Controller on PIC32CM M0+ Devices](https://github.com/microchip-pic-avr-examples/pic32cmjh-basic-ptc-mplab-harmony)
297
+
- [Getting Started with SERCOM (I²C) Communication on PIC32CM M0+ Devices](https://github.com/microchip-pic-avr-examples/pic32cmjh-basic-i2c-mplab-harmony)
298
+
- [Getting Started with SERCOM (SPI) Communication on PIC32CM M0+ Devices](https://github.com/microchip-pic-avr-examples/pic32cmjh-basic-spi-mplab-harmony)
0 commit comments