[Kinetis] 【K64F】基于mbed的串口

[复制链接]
1733|3
 楼主| 奥德赛 发表于 2016-1-22 21:15 | 显示全部楼层 |阅读模式
FRDM-K64F板载 MK64FN1M0VLL12 100pin LQFP 封装的 芯片,该MCU包含5组串口,分别是
  1. UART0_RX        PTB16   OpenSDAv2 (虚拟串口)
  2. UART0_TX        PTB17   OpenSDAv2 (虚拟串口)

  3. UART1_RX        PTC3    (D7)
  4. UART1_TX        PTC4    (D9)

  5. UART2_RX        PTD2    (D11)
  6. UART2_TX        PTD3    (D12)

  7. UART3_RX        PTC16   (D0) RX
  8. UART3_TX        PTC17   (D1) TX

  9. UART4_RX        PTC14   (BT_TX)
  10. UART4_TX        PTC15   (BT_RX)
大家可以看我的第一篇帖子里关于FRDM-K64F GPIO驱动RGB中mbed pin name.pdf文档中各管脚的定义。
在这里我们首先通过openSDA的虚拟串口和PC机通信,即UART0

  1. #include "mbed.h"

  2. DigitalOut myled(LED_BLUE);
  3. Serial pc(USBTX, USBRX);

  4. int main()
  5. {
  6.     int i = 0;
  7.     pc.printf("Hello **!\n");

  8.     while (true) {
  9.         wait(0.5f); // wait a small period of time
  10.         pc.printf("%d \n", i); // print the value of variable i
  11.         i++; // increment the variable
  12.         myled = !myled; // toggle a led
  13.     }
  14. }



 楼主| 奥德赛 发表于 2016-1-22 21:16 | 显示全部楼层
通过secureCRT观察其接收到的数据

程序运行后会通过虚拟串口打印讯息,每一次打印时会将RGB的蓝色 LED 状态反向。
在这里
  1. MBED 对 FRDM-K64F 的 UART0 管脚定义为
  2. USBTX = PTB17
  3. 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);
  1. #include "mbed.h"

  2. DigitalOut myled(LED_GREEN);
  3. //Serial pc(USBTX, USBRX);
  4. Serial uart0(PTB17, PTB16);
  5. Serial uart1(PTC4, PTC3);
  6. Serial uart2(PTD3, PTD2);
  7. Serial uart3(PTC17, PTC16);

  8. int main()
  9. {
  10.     int i = 0;
  11.     uart0.printf("Hello World! UART0\n");
  12.     uart1.printf("Hello **! UART1\n");
  13.     uart2.printf("Hello freescale! UART2\n");
  14.     uart3.printf("Hello eeboard! UART3\n");

  15.     while (true) {
  16.         wait(0.5f); // wait a small period of time
  17.         uart0.printf("%d \n", i); // print the value of variable i
  18.         uart1.printf("%d \n", i);
  19.         uart2.printf("%d \n", i);
  20.         uart3.printf("%d \n", i);
  21.         i++; // increment the variable
  22.         myled = !myled; // toggle a led
  23.     }
  24. }


 楼主| 奥德赛 发表于 2016-1-22 21:18 | 显示全部楼层
大家可以用3条串口线同时显示 除UART0外的另外3 个串口输出。
需要强调的是UART4是连接到 J199 接头的,这个接头是保留给蓝牙模块使用,大家可以暂时不用管。
serial-2.jpg (35.7 KB, 下载次数: 0)
下载附件
2015-10-26 21:21 上传











neeringstu 发表于 2016-1-23 20:49 | 显示全部楼层

有没有测试过,波特率为115200的串口真的能达到这个速率吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

46

主题

397

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部