在程序中使用 4 个串口:#include "mbed.h"
DigitalOut myled(LED_GREEN);
//Serial pc(USBTX, USBRX);
Serial pc(PTB17, PTB16);
Serial uart1(PTC4, PTC3);
Serial uart2(PTD3, PTD2);
Serial uart3(PTC17, PTC16);
int main()
{
int i = 0;
pc.printf("Hello World!\n");
uart1.printf("Hello World! UART1\n");
uart2.printf("Hello World! UART2\n");
uart3.printf("Hello World! UART3\n");
while (true) {
wait(0.5f); // wait a small period of time
pc.printf("%d \n", i); // print the value of variable i
uart1.printf("%d \n", i);
uart2.printf("%d \n", i);
uart3.printf("%d \n", i);
i++; // increment the variable
myled = !myled; // toggle a led
}
}
|