This is for those that are having a hard time getting started with the serial ports and UARTs:
(Code below can test passing data between the ports at 1M baud)
I bought the Portenta-H7 and the Portenta-Breakout-Board hoping to be able to use four fast serial ports while also using the programming port separately. The H7 offers that.
My thanks to Jeremy Ellis' github information.
Most Excellent Portenta Dev URL
Modified code (I'm a little messy, but it works):
/* Portenta Serial UART
* Code modified from:
Thank you, Jeremy Ellis
https://github.com/hpssjellis/portenta-pro-community-solutions/blob/main/examples/dot1-portentaH7-examples/dot19-cores-uart-serial-com/dot198-uart-serialtransfer/dot198-uart-serialtransfer.ino
* Code modified from:
Thank you, Jeremy Ellis
//This, go there... ---> https://github.com/hpssjellis/portenta-pro-community-solutions
* ================================================================================
*
* * UART Information for the PortentaH7
*
* UART myUART0(PA_0, PI_9, NC, NC); // TX, RX, RTS, CTC NOTE: NC means not connected
* UART myUART1(PA_9, PA_10, NC, NC); // pin D14 TX, pin D13 RX same as pre-defined Serial1
* UART myUART2(PG_14, PG_9, NC, NC);
* UART myUART3(PJ_8, PJ_9, NC, NC);
* UART myUART6(PC_6, PC_7, NC, NC); // pin D5 TX, pin D4 RX
* UART myUART8(NC, PA_8, NC, NC); // pin D6 RX only can receive
*
*/
//#include <Arduino.h>
//#include <Arduino_PortentaBreakout.h>
//#include "SerialTransfer.h"
//////////////////// Start All Core M7 Programing /////////////////////
#ifdef CORE_CM7
//--------------------------------------------- NOTE ------------------------------------------------------
// I used the Portenta Breakout Board and soldered some jumpers on the four UART breakouts.
// Everything worked.
//
// UART Test1 is a bidirectional test of UART0 and UART1
// UART Test2 is a bidirectional test of UART2 and UART3
//--assign Serial UART
//https://github.com/hpssjellis/portenta-pro-community-solutions <--- Most excellent URL
//Thank you, Jeremy Ellis.
//UART myUART0(PA_0, PI_9, NC, NC); // put this back to test with with myUART1 on M4 Test1 - worked 20230218
UART myUART2(PG_14, PG_9, NC, NC); // put this back to test with with myUART3 on M4 Test2 - worked 20230218
int i=65; //(char)"A";
void setup() {
pinMode(LEDR, OUTPUT); // LEDB = blue, LEDG or LED_BUILTIN = green, LEDR = red
bootM4();
Serial.begin(2000000);
//myUART0.begin(1000000);
//myUART0.setTimeout(10);
myUART2.begin(1000000);
myUART2.setTimeout(10);
}
void loop() {
if (i > 90){i = 65;} // ascii 65 = letter A, ascii 90 = letter Z
//myUART0.write((char)i++); // ascii code for numbers A to Z
myUART2.write((char)i++); // ascii code for numbers A to Z
//if (myUART0.available()) {
if (myUART2.available()) {
digitalWrite(LEDR, !digitalRead(LEDR)); // switch on / off
do { // Read all to clear buffer
//Serial.write(myUART0.read()); // Read it and send it out Serial (USB)
Serial.write(myUART2.read()); // Read it and send it out Serial (USB)
//} while (myUART0.available());
} while (myUART2.available());
}
Serial.write("\n"); // Read it and send it out Serial (USB)
delay(500);
}
#endif
//////////////////// End All Core M7 Programing /////////////////////
//////////////////// Start All Core M4 Programing /////////////////////
#ifdef CORE_CM4
int myCount=48; //48 = ascii 0, 58 ascii 9
char c;
//--assign Serial UART
//https://github.com/hpssjellis/portenta-pro-community-solutions <--- Most excellent URL
//Thank you, Jeremy Ellis.
//UART myUART1(PA_9, PA_10, NC, NC); // put this back to test with with myUART0 on M7 Test1 - worked 20230218
UART myUART3(PJ_8, PJ_9, NC, NC); // put this back to test with with myUART2 on M7 Test2 - worked 20230218
void setup() {
pinMode(LEDB, OUTPUT); // LEDB = blue, LEDG or LED_BUILTIN = green, LEDR = red
// Serial.begin(115200); // no serial monitor on M4 core without RPC
//Most excellent URL ---> https://github.com/hpssjellis/portenta-pro-community-solutions
//myUART1.begin(1000000);
//myUART1.setTimeout(10);
myUART3.begin(1000000);
myUART3.setTimeout(10);
}
void loop() {
if (myCount >= 58){myCount = 48;} // ascii 48 = number 0, ascii 58 = number 9
char x = (char)myCount++;
//myUART1.write(x);
//myUART1.write(c);
myUART3.write(x);
myUART3.write(c);
//if (myUART1.available()) {
if (myUART3.available()) {
digitalWrite(LEDB, !digitalRead(LEDB)); // switch on / off
do { // Read all to clear buffer
//c = myUART1.read(); // c
c = myUART3.read(); // c
//} while (myUART1.available());
} while (myUART3.available());
}
delay(500);
}
#endif
//////////////////// End All Core M4 Programing /////////////////////