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.
Diff: uart.cpp
- Revision:
- 0:ecd925601fc6
- Child:
- 1:15ab74f0d0f1
- Child:
- 2:f0fbb23b4605
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/uart.cpp Fri Nov 23 07:27:43 2018 +0000
@@ -0,0 +1,48 @@
+#include "typedef.h"
+#include "uart.h"
+
+//#define WIREED_SERIAL
+
+//シリアルポートインスタンス
+#ifdef WIREED_SERIAL
+ Serial sp(USBTX, USBRX); //有線のポート
+ #define BAUD_RATE 9600
+#else
+ Serial sp(p9, p10);//TWILITEをモジュールを接続したポート
+ #define BAUD_RATE 115200
+#endif
+
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+// UART 受信割り込みハンドラ
+//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+void uartRxIntHndler(){
+ //1Byte抜き出す
+ UCHAR buf = sp.getc();
+ //エコーバック
+ sp.putc(buf);
+ //コマンドバッファに突っ込む
+ //commandPush(buf);
+}
+
+//=============================================================
+//初期設定
+//=============================================================
+void uartInit(){
+ //ボーレート設定
+ sp.baud(BAUD_RATE);
+
+ //受信割り込みハンドラ登録
+ sp.attach
+ (uartRxIntHndler //登録するハンドラ
+ ,Serial::RxIrq //割り込み要因
+ );
+
+ sp.printf("***********\r\n");
+ sp.printf("UART open!!\r\n");
+ sp.printf("-----------\r\n");
+ sp.printf("short = %d\r\n" ,sizeof(unsigned short) );
+ sp.printf("int = %d\r\n" ,sizeof(unsigned int) );
+ sp.printf("long = %d\r\n" ,sizeof(unsigned long) );
+ sp.printf("***********\r\n");
+
+}