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: content/hardware/04.pro/boards/portenta-c33/tutorials/user-manual/content.md
+41-30Lines changed: 41 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -702,30 +702,38 @@ The Portenta C33 supports UART communication. The pins used in the Portenta C33
702
702
|`92`|`P603`|
703
703
|`93`|`P604`|
704
704
705
-
Please refer to the board pinout section of the user manual to find them on the board. The built-in ([Serial](https://www.arduino.cc/reference/en/language/functions/communication/serial/)) library functions can use the UART pins.
705
+
***Please refer to the board pinout section of the user manual to find them on the board. The built-in [Serial](https://www.arduino.cc/reference/en/language/functions/communication/serial/) library functions can use the UART pins.***
706
706
707
-
#### UART Initialization
707
+
The `Arduino Renesas Core` has a built-in library that lets you use the UART communication, the `Serial` library, right out of the box. Let's walk through an example sketch demonstrating some of the module's capabilities.
708
708
709
-
To begin with UART communication, you'll need to configure it first. In the `setup()` function, set the baud rate (bits per second) for UART communication:
709
+
The example sketch below showcases how to configure UART, read incoming data, and transmit data with the Portenta C33 board, which are common tasks for serial communication.
710
710
711
711
```arduino
712
-
// Start UART communication at 9600 baud
713
-
Serial.begin(9600);
714
-
```
715
-
716
-
#### Receive Data
712
+
/**
713
+
UART Communication
714
+
Name: UARTCommunication.ino
715
+
Purpose: This sketch demonstrates UART communication on the Portenta C33
717
716
718
-
To read incoming data, you can use a `while()` loop to continuously check for available data with the `Serial.available()` function and read individual characters with the `Serial.read()` function.
717
+
@author Arduino Product Experience Team
718
+
@version 1.0 03/06/24
719
+
*/
719
720
720
-
The example sketch shown below stores incoming characters in a String variable and processes the data when a line-ending character is received:
721
+
// Include the necessary libraries for UART communication
722
+
#include <Arduino.h>
721
723
722
-
```arduino
723
724
// Variable for storing incoming data
724
725
String incoming = "";
725
726
726
-
// Start UART communication at 9600 baud
727
727
void setup() {
728
+
// Begin serial communication at a baud rate of 9600
728
729
Serial.begin(9600);
730
+
731
+
// Wait for the serial port to connect
732
+
// This is necessary for boards that have native USB
733
+
while (!Serial) {}
734
+
735
+
// Print a message to the Serial Monitor to indicate setup is complete
736
+
Serial.println("UART Communication Setup Complete");
729
737
}
730
738
731
739
void loop() {
@@ -747,33 +755,36 @@ void loop() {
747
755
incoming += c;
748
756
}
749
757
}
758
+
759
+
// Example of transmitting data
760
+
// Transmit the string "Hello world!" every second
761
+
// Wait for 1 second before sending again
762
+
Serial.println("Hello world!");
763
+
delay(1000);
750
764
}
751
765
752
-
// Function to process the received data
766
+
/**
767
+
Processes the received data
768
+
This function can be modified to perform different actions based on the received data
769
+
770
+
@param data The received data as a String
771
+
@return none
772
+
*/
753
773
void processData(String data) {
754
-
// Example: Print the received data to the Arduino IDE Serial Monitor
755
-
Serial.println("Received: " + data);
774
+
// Print the received data to the Arduino IDE Serial Monitor
775
+
Serial.println("- Received: " + data);
756
776
}
757
777
```
758
778
759
-
#### Transmit Data
760
-
761
-
To transmit data to another device via UART, you can use the `Serial.write()` function:
779
+
Let's analyze the example sketch. First, the necessary configurations are made:
762
780
763
-
```arduino
764
-
// Transmit the string "Hello world!
765
-
Serial.write("Hello world!");
766
-
```
781
+
- The UART communication is initialized at a baud rate of 9600.
782
+
- A loop continuously checks for available data and reads individual characters, storing them in a `String` variable.
783
+
- A newline character indicates the end of a message, triggering the processing function.
767
784
768
-
You can also use the `Serial.print()` and `Serial.println()` functions to send a String without a newline character or followed by a newline character:
785
+
The `processData()` function is called to process the received data. This example simply prints the data to the Arduino IDE's Serial Monitor. You can modify this function to perform different actions based on the received data. Finally, the example sketch shows how to send data using the `Serial.println()` function, which transmits the string `Hello world!` every second.
769
786
770
-
```arduino
771
-
// Transmit the string "Hello world!"
772
-
Serial.print("Hello world!");
773
-
774
-
// Transmit the string "Hello world!" followed by a newline character
775
-
Serial.println("Hello world!");
776
-
```
787
+
You should see the following output in the Arduino IDE's Serial Monitor:
0 commit comments