我正在使用连接到 Portenta H7 (https://store.arduino.cc/products) 的 Portenta Arduino 分线板 (https://store.arduino.cc/products/arduino-portenta-breakout) /portenta-h7)用于我正在从事的一个项目。该项目要求我使用三个 GPS 传感器(Adafruit Ultimate GPS 传感器,https://learn.adafruit.com/adafruit-ultimate-gps/overview)并将每个传感器连接到 Portenta 分线板上各自的 UART 端口。我只使用 UART0、UART1 和 UART2(分别是 Serial、Serial1 和 Serial2)。
为了能够获取数据,我一直在使用 Arduino IDE 中的示例代码:
// (e.g. GPS for Leonardo, Flora or FeatherWing)
//
// This code shows how to test a passthru between USB and hardware serial
//
// Tested and works great with the Adafruit GPS FeatherWing
// ------> https://www.adafruit.com/products/3133
// or Flora GPS
// ------> https://www.adafruit.com/products/1059
// but also works with the shield, breakout
// ------> https://www.adafruit.com/products/1272
// ------> https://www.adafruit.com/products/746
//
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada
// what's the name of the hardware serial port?
#define GPSSerial Serial1
void setup() {
// make this baud rate fast enough to we aren't waiting on it
Serial.begin(115200);
// wait for hardware serial to appear
while (!Serial) delay(10);
// 9600 baud is the default rate for the Ultimate GPS
GPSSerial.begin(9600);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
GPSSerial.write(c);
}
if (GPSSerial.available()) {
char c = GPSSerial.read();
Serial.write(c);
}
}
此代码适用于 Serial1,当我将 GPS 连接到分线板的 UART1 端口时,我会获取数据。当我调用 Serial 或 Serial2 时,更改
#define GPSSerial Serial1
到 #define GPSSerial Serial
或 #define GPSSerial Serial2
代码将毫无错误地上传,但当 GPS 连接到相应的 UART 端口(UART0 和 UART2)时,我没有从 GPS 接收任何数据。
我检查了数据是否自动仅来自 UART1 端口,但当我调用 Serial 或 Serial2 时,它不会显示任何内容,这应该是预期的。
有谁知道如何处理这个问题吗? UART0 和 UART2 端口是否无法将数据传输到 Portenta H7 板,这可能是我看不到任何数据的原因?
如果我需要澄清任何事情,请告诉我。
我刚刚花了一天时间来追踪同样的问题。原因是 Arduino 将这些 UART 端口的命名约定搞得一团糟。请参阅下表。我根据 Portenta 原理图 和 分线板原理图 创建了此表。
分线示意图 | P。原理图@J1,J2 | P。示意图@微 | 微型引脚(tx、rx) | pins_arduino.h |
---|---|---|---|---|
UART0 | 系列2 | UART4 | (PA0,PI9) | 未定义 |
UART1 | 系列1 | LPU艺术 | (PA9,PA10) | 也许是连续剧 1? |
UART2 | 系列3 | UART6 | (PG14,PG9) | 未定义 |
UART3 | 系列4 | UART8 | (PJ8,PJ9) | 连载3 |
不幸的是,如您所见,pins_arduino.h 中的内置串行定义不适用于分线板。 (除非您使用串行 1 或串行 3)
如果你想使用这些其他串口,你需要定义自己的串口,这实际上并不难。您只需手动指定引脚即可。
#include "Serial.h"
UART UART0Breakout = UART(PA_0, PI_9);
UART UART2Breakout = UART(PG_14, PG_9);
void setup()
{
UART0Breakout.begin(115200);
UART2Breakout.begin(115200);
}
希望这对您有帮助!这确实让我抓狂了一段时间。不幸的是,我用于分线板的原理图的注释并不像我在此处链接的原理图那么好(我在编写此答案时发现了它)。