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@18:5aa48aec9cae, 2018-12-01 (annotated)
- Committer:
- takeru0x1103
- Date:
- Sat Dec 01 14:03:08 2018 +0000
- Revision:
- 18:5aa48aec9cae
- Parent:
- 17:f9610f3cfa1b
- Child:
- 19:4b0fe9a5ec38
??????????PID????????????
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 | 18:5aa48aec9cae | 3 | #include "hbCommand.h" |
| takeru0x1103 | 0:ecd925601fc6 | 4 | |
| takeru0x1103 | 8:1ca49cb18290 | 5 | //ログ吐出し様シリアルポートインスタンス |
| takeru0x1103 | 8:1ca49cb18290 | 6 | //---------------------------------- |
| takeru0x1103 | 8:1ca49cb18290 | 7 | #define WIREED_SERIAL |
| takeru0x1103 | 0:ecd925601fc6 | 8 | #ifdef WIREED_SERIAL |
| takeru0x1103 | 0:ecd925601fc6 | 9 | Serial sp(USBTX, USBRX); //有線のポート |
| takeru0x1103 | 8:1ca49cb18290 | 10 | #define BAUD_RATE 115200 |
| takeru0x1103 | 0:ecd925601fc6 | 11 | #else |
| takeru0x1103 | 0:ecd925601fc6 | 12 | Serial sp(p9, p10);//TWILITEをモジュールを接続したポート |
| takeru0x1103 | 0:ecd925601fc6 | 13 | #define BAUD_RATE 115200 |
| takeru0x1103 | 0:ecd925601fc6 | 14 | #endif |
| MasashiNomura | 7:bfbbf605be43 | 15 | |
| MasashiNomura | 14:76a56d517103 | 16 | //Serial sp46Axis(p28,p27); |
| MasashiNomura | 7:bfbbf605be43 | 17 | |
| takeru0x1103 | 8:1ca49cb18290 | 18 | //Asciiコード |
| takeru0x1103 | 8:1ca49cb18290 | 19 | #define CR 0x0D |
| takeru0x1103 | 8:1ca49cb18290 | 20 | #define LF 0x0A |
| takeru0x1103 | 0:ecd925601fc6 | 21 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| takeru0x1103 | 0:ecd925601fc6 | 22 | // UART 受信割り込みハンドラ |
| takeru0x1103 | 0:ecd925601fc6 | 23 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| takeru0x1103 | 0:ecd925601fc6 | 24 | void uartRxIntHndler(){ |
| takeru0x1103 | 0:ecd925601fc6 | 25 | //1Byte抜き出す |
| takeru0x1103 | 0:ecd925601fc6 | 26 | UCHAR buf = sp.getc(); |
| takeru0x1103 | 0:ecd925601fc6 | 27 | //エコーバック |
| takeru0x1103 | 17:f9610f3cfa1b | 28 | sp.putc(buf); |
| takeru0x1103 | 0:ecd925601fc6 | 29 | //コマンドバッファに突っ込む |
| takeru0x1103 | 1:15ab74f0d0f1 | 30 | commandPush(buf); |
| takeru0x1103 | 0:ecd925601fc6 | 31 | } |
| takeru0x1103 | 0:ecd925601fc6 | 32 | |
| takeru0x1103 | 0:ecd925601fc6 | 33 | //============================================================= |
| takeru0x1103 | 0:ecd925601fc6 | 34 | //初期設定 |
| takeru0x1103 | 0:ecd925601fc6 | 35 | //============================================================= |
| takeru0x1103 | 0:ecd925601fc6 | 36 | void uartInit(){ |
| takeru0x1103 | 0:ecd925601fc6 | 37 | //ボーレート設定 |
| takeru0x1103 | 0:ecd925601fc6 | 38 | sp.baud(BAUD_RATE); |
| takeru0x1103 | 0:ecd925601fc6 | 39 | |
| takeru0x1103 | 8:1ca49cb18290 | 40 | //受信割り込みハンドラ登録(登録するハンドラ,割り込み要因) |
| takeru0x1103 | 8:1ca49cb18290 | 41 | sp.attach(uartRxIntHndler,Serial::RxIrq); |
| takeru0x1103 | 0:ecd925601fc6 | 42 | |
| takeru0x1103 | 0:ecd925601fc6 | 43 | sp.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 44 | sp.printf("UART open!!\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 45 | sp.printf("-----------\r\n"); |
| takeru0x1103 | 18:5aa48aec9cae | 46 | sp.printf("INT16 = %d\r\n" ,sizeof(INT16) ); |
| takeru0x1103 | 18:5aa48aec9cae | 47 | sp.printf("unsigned int = %d\r\n" ,sizeof(unsigned int) ); |
| takeru0x1103 | 18:5aa48aec9cae | 48 | sp.printf("long = %d\r\n" ,sizeof(unsigned long) ); |
| takeru0x1103 | 18:5aa48aec9cae | 49 | sp.printf("unsigned int = %d\r\n" ,sizeof(unsigned int) ); |
| takeru0x1103 | 0:ecd925601fc6 | 50 | sp.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 51 | } |