在线时间98 小时
UID183307
注册时间2010-4-22
NXP金币0
TA的每日心情 | 奋斗 2016-12-13 20:56 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]初来乍到
金牌会员
 
- 积分
- 1217
- 最后登录
- 2020-7-26
|
FRDM-K64F板载 MK64FN1M0VLL12 100pin LQFP 封装的 芯片,该MCU包含5组串口,分别是
- UART0_RX PTB16 OpenSDAv2 (虚拟串口)
- UART0_TX PTB17 OpenSDAv2 (虚拟串口)
- UART1_RX PTC3 (D7)
- UART1_TX PTC4 (D9)
- UART2_RX PTD2 (D11)
- UART2_TX PTD3 (D12)
- UART3_RX PTC16 (D0) RX
- UART3_TX PTC17 (D1) TX
- UART4_RX PTC14 (BT_TX)
- UART4_TX PTC15 (BT_RX)
复制代码 大家可以看我的第一篇帖子里关于FRDM-K64F GPIO驱动RGB中mbed pin name.pdf文档中各管脚的定义。
在这里我们首先通过openSDA的虚拟串口和PC机通信,即UART0
- #include "mbed.h"
- DigitalOut myled(LED_BLUE);
- Serial pc(USBTX, USBRX);
- int main()
- {
- int i = 0;
- pc.printf("Hello eefocus!\n");
- while (true) {
- wait(0.5f); // wait a small period of time
- pc.printf("%d \n", i); // print the value of variable i
- i++; // increment the variable
- myled = !myled; // toggle a led
- }
- }
复制代码 通过secureCRT观察其接收到的数据
程序运行后会通过虚拟串口打印讯息,每一次打印时会将RGB的蓝色 LED 状态反向。
在这里
- MBED 对 FRDM-K64F 的 UART0 管脚定义为
- USBTX = PTB17
- USBRX = PTB16
复制代码 因此,Serial pc(USBTX, USBRX); 与 Serial pc(PTB17, PTB16); 是等效的!
同理,我们要使用其他的串口也可以用相同的方式定义:
如要使用 UART1,可定义为Serial uart1(PTC4, PTC3);
如要使用 UART2,可定义为Serial uart2(PTD3, PTD2);
如要使用 UART3,可定义为Serial uart3(PTC17, PTC16);
- #include "mbed.h"
- DigitalOut myled(LED_GREEN);
- //Serial pc(USBTX, USBRX);
- Serial uart0(PTB17, PTB16);
- Serial uart1(PTC4, PTC3);
- Serial uart2(PTD3, PTD2);
- Serial uart3(PTC17, PTC16);
- int main()
- {
- int i = 0;
- uart0.printf("Hello World! UART0\n");
- uart1.printf("Hello eefocus! UART1\n");
- uart2.printf("Hello freescale! UART2\n");
- uart3.printf("Hello eeboard! UART3\n");
- while (true) {
- wait(0.5f); // wait a small period of time
- uart0.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
- }
- }
复制代码 大家可以用3条串口线同时显示 除UART0外的另外3 个串口输出。
需要强调的是UART4是连接到 J199 接头的,这个接头是保留给蓝牙模块使用,大家可以暂时不用管。
|
|