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.
uart.cpp@0:ecd925601fc6, 2018-11-23 (annotated)
- Committer:
- takeru0x1103
- Date:
- Fri Nov 23 07:27:43 2018 +0000
- Revision:
- 0:ecd925601fc6
- Child:
- 1:15ab74f0d0f1
- Child:
- 2:f0fbb23b4605
????????????????????
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| takeru0x1103 | 0:ecd925601fc6 | 1 | #include "typedef.h" |
| takeru0x1103 | 0:ecd925601fc6 | 2 | #include "uart.h" |
| takeru0x1103 | 0:ecd925601fc6 | 3 | |
| takeru0x1103 | 0:ecd925601fc6 | 4 | //#define WIREED_SERIAL |
| takeru0x1103 | 0:ecd925601fc6 | 5 | |
| takeru0x1103 | 0:ecd925601fc6 | 6 | //シリアルポートインスタンス |
| takeru0x1103 | 0:ecd925601fc6 | 7 | #ifdef WIREED_SERIAL |
| takeru0x1103 | 0:ecd925601fc6 | 8 | Serial sp(USBTX, USBRX); //有線のポート |
| takeru0x1103 | 0:ecd925601fc6 | 9 | #define BAUD_RATE 9600 |
| takeru0x1103 | 0:ecd925601fc6 | 10 | #else |
| takeru0x1103 | 0:ecd925601fc6 | 11 | Serial sp(p9, p10);//TWILITEをモジュールを接続したポート |
| takeru0x1103 | 0:ecd925601fc6 | 12 | #define BAUD_RATE 115200 |
| takeru0x1103 | 0:ecd925601fc6 | 13 | #endif |
| takeru0x1103 | 0:ecd925601fc6 | 14 | |
| takeru0x1103 | 0:ecd925601fc6 | 15 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| takeru0x1103 | 0:ecd925601fc6 | 16 | // UART 受信割り込みハンドラ |
| takeru0x1103 | 0:ecd925601fc6 | 17 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| takeru0x1103 | 0:ecd925601fc6 | 18 | void uartRxIntHndler(){ |
| takeru0x1103 | 0:ecd925601fc6 | 19 | //1Byte抜き出す |
| takeru0x1103 | 0:ecd925601fc6 | 20 | UCHAR buf = sp.getc(); |
| takeru0x1103 | 0:ecd925601fc6 | 21 | //エコーバック |
| takeru0x1103 | 0:ecd925601fc6 | 22 | sp.putc(buf); |
| takeru0x1103 | 0:ecd925601fc6 | 23 | //コマンドバッファに突っ込む |
| takeru0x1103 | 0:ecd925601fc6 | 24 | //commandPush(buf); |
| takeru0x1103 | 0:ecd925601fc6 | 25 | } |
| takeru0x1103 | 0:ecd925601fc6 | 26 | |
| takeru0x1103 | 0:ecd925601fc6 | 27 | //============================================================= |
| takeru0x1103 | 0:ecd925601fc6 | 28 | //初期設定 |
| takeru0x1103 | 0:ecd925601fc6 | 29 | //============================================================= |
| takeru0x1103 | 0:ecd925601fc6 | 30 | void uartInit(){ |
| takeru0x1103 | 0:ecd925601fc6 | 31 | //ボーレート設定 |
| takeru0x1103 | 0:ecd925601fc6 | 32 | sp.baud(BAUD_RATE); |
| takeru0x1103 | 0:ecd925601fc6 | 33 | |
| takeru0x1103 | 0:ecd925601fc6 | 34 | //受信割り込みハンドラ登録 |
| takeru0x1103 | 0:ecd925601fc6 | 35 | sp.attach |
| takeru0x1103 | 0:ecd925601fc6 | 36 | (uartRxIntHndler //登録するハンドラ |
| takeru0x1103 | 0:ecd925601fc6 | 37 | ,Serial::RxIrq //割り込み要因 |
| takeru0x1103 | 0:ecd925601fc6 | 38 | ); |
| takeru0x1103 | 0:ecd925601fc6 | 39 | |
| takeru0x1103 | 0:ecd925601fc6 | 40 | sp.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 41 | sp.printf("UART open!!\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 42 | sp.printf("-----------\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 43 | sp.printf("short = %d\r\n" ,sizeof(unsigned short) ); |
| takeru0x1103 | 0:ecd925601fc6 | 44 | sp.printf("int = %d\r\n" ,sizeof(unsigned int) ); |
| takeru0x1103 | 0:ecd925601fc6 | 45 | sp.printf("long = %d\r\n" ,sizeof(unsigned long) ); |
| takeru0x1103 | 0:ecd925601fc6 | 46 | sp.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 47 | |
| takeru0x1103 | 0:ecd925601fc6 | 48 | } |