Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:b78c70e272ae, committed 2016-10-20
- Comitter:
- anywill
- Date:
- Thu Oct 20 09:11:55 2016 +0000
- Parent:
- 0:a854d9a733ca
- Child:
- 2:db3ce8717e38
- Commit message:
- uart2uart
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 19 10:03:45 2016 +0000
+++ b/main.cpp Thu Oct 20 09:11:55 2016 +0000
@@ -1,29 +1,22 @@
+//平台nucleo 70r+mbed
+//USB虚拟串口与PC串口通信
+//波特率9600,无奇偶校验
#include "mbed.h"
-//#include "TimeManagement.h"
-//DigitalOut myled(LED1);
-AnalogIn in(A5);
-Serial pc(USBTX,USBRX);
+Serial pc(SERIAL_TX, SERIAL_RX); // 虚拟 USART2 tx, rx
+Serial device(PB_6, PA_10); // PC机usb转TTL CP2102 USART1 tx, rx
+
int main()
{
- float value;
-
- while(1)
- {
- value=in;
- pc.printf("\n \r Analog value %f", value);
- float cel=value*100 ;//x读取A0口的电压值 float vol = n * (5.0 / 4096.0*100);
- //读取A0口的电压值 float vol = n * (5.0 / 1023.0*100);
-
- pc.printf("\n \r Temperature value %f", cel);
-
- // pc.printf("%s ", time);
-
- wait(1.0);
-
- }
-
-
-
+ while(1)
+ {
+ if(pc.readable())
+ {
+ device.putc(pc.getc()); // 从虚拟串口接收数据,并发给PC
+
+ }
+ if(device.readable())
+ {
+ pc.putc(device.getc()); // 从PC物理串口接收数据,并发给虚拟串口
+ }
+ }
}
-
-