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@2:f0fbb23b4605, 2018-11-23 (annotated)
- Committer:
- MasashiNomura
- Date:
- Fri Nov 23 08:01:44 2018 +0000
- Revision:
- 2:f0fbb23b4605
- Parent:
- 0:ecd925601fc6
- Child:
- 4:7aa8cf0dd56f
uart.cpp?Serial?sp46Axis???; ??????????;
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 |
| MasashiNomura | 2:f0fbb23b4605 | 14 | |
| MasashiNomura | 2:f0fbb23b4605 | 15 | Serial sp46Axis(p28,p27); |
| MasashiNomura | 2:f0fbb23b4605 | 16 | #define BAUD_RATE4_6AXIS 115200 |
| MasashiNomura | 2:f0fbb23b4605 | 17 | |
| takeru0x1103 | 0:ecd925601fc6 | 18 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| takeru0x1103 | 0:ecd925601fc6 | 19 | // UART 受信割り込みハンドラ |
| takeru0x1103 | 0:ecd925601fc6 | 20 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| takeru0x1103 | 0:ecd925601fc6 | 21 | void uartRxIntHndler(){ |
| takeru0x1103 | 0:ecd925601fc6 | 22 | //1Byte抜き出す |
| takeru0x1103 | 0:ecd925601fc6 | 23 | UCHAR buf = sp.getc(); |
| takeru0x1103 | 0:ecd925601fc6 | 24 | //エコーバック |
| takeru0x1103 | 0:ecd925601fc6 | 25 | sp.putc(buf); |
| takeru0x1103 | 0:ecd925601fc6 | 26 | //コマンドバッファに突っ込む |
| takeru0x1103 | 0:ecd925601fc6 | 27 | //commandPush(buf); |
| takeru0x1103 | 0:ecd925601fc6 | 28 | } |
| takeru0x1103 | 0:ecd925601fc6 | 29 | |
| MasashiNomura | 2:f0fbb23b4605 | 30 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| MasashiNomura | 2:f0fbb23b4605 | 31 | // UART 受信割り込みハンドラ for Arduino UNO(Six Axis Sensor) |
| MasashiNomura | 2:f0fbb23b4605 | 32 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| MasashiNomura | 2:f0fbb23b4605 | 33 | void uartRxIntHndler46AxisS(){ |
| MasashiNomura | 2:f0fbb23b4605 | 34 | //1Byte抜き出す |
| MasashiNomura | 2:f0fbb23b4605 | 35 | UCHAR buf = sp46Axis.getc(); |
| MasashiNomura | 2:f0fbb23b4605 | 36 | //エコーバック |
| MasashiNomura | 2:f0fbb23b4605 | 37 | sp46Axis.putc(buf); |
| MasashiNomura | 2:f0fbb23b4605 | 38 | sp.putc(buf); |
| MasashiNomura | 2:f0fbb23b4605 | 39 | //コマンドバッファに突っ込む |
| MasashiNomura | 2:f0fbb23b4605 | 40 | //commandPush(buf); |
| MasashiNomura | 2:f0fbb23b4605 | 41 | } |
| MasashiNomura | 2:f0fbb23b4605 | 42 | |
| takeru0x1103 | 0:ecd925601fc6 | 43 | //============================================================= |
| takeru0x1103 | 0:ecd925601fc6 | 44 | //初期設定 |
| takeru0x1103 | 0:ecd925601fc6 | 45 | //============================================================= |
| takeru0x1103 | 0:ecd925601fc6 | 46 | void uartInit(){ |
| takeru0x1103 | 0:ecd925601fc6 | 47 | //ボーレート設定 |
| takeru0x1103 | 0:ecd925601fc6 | 48 | sp.baud(BAUD_RATE); |
| takeru0x1103 | 0:ecd925601fc6 | 49 | |
| takeru0x1103 | 0:ecd925601fc6 | 50 | //受信割り込みハンドラ登録 |
| takeru0x1103 | 0:ecd925601fc6 | 51 | sp.attach |
| takeru0x1103 | 0:ecd925601fc6 | 52 | (uartRxIntHndler //登録するハンドラ |
| takeru0x1103 | 0:ecd925601fc6 | 53 | ,Serial::RxIrq //割り込み要因 |
| takeru0x1103 | 0:ecd925601fc6 | 54 | ); |
| takeru0x1103 | 0:ecd925601fc6 | 55 | |
| takeru0x1103 | 0:ecd925601fc6 | 56 | sp.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 57 | sp.printf("UART open!!\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 58 | sp.printf("-----------\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 59 | sp.printf("short = %d\r\n" ,sizeof(unsigned short) ); |
| takeru0x1103 | 0:ecd925601fc6 | 60 | sp.printf("int = %d\r\n" ,sizeof(unsigned int) ); |
| takeru0x1103 | 0:ecd925601fc6 | 61 | sp.printf("long = %d\r\n" ,sizeof(unsigned long) ); |
| takeru0x1103 | 0:ecd925601fc6 | 62 | sp.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 63 | |
| MasashiNomura | 2:f0fbb23b4605 | 64 | // for 6Axis Sensor |
| MasashiNomura | 2:f0fbb23b4605 | 65 | //ボーレート設定 |
| MasashiNomura | 2:f0fbb23b4605 | 66 | sp46Axis.baud(BAUD_RATE4_6AXIS); |
| MasashiNomura | 2:f0fbb23b4605 | 67 | |
| MasashiNomura | 2:f0fbb23b4605 | 68 | //受信割り込みハンドラ登録 |
| MasashiNomura | 2:f0fbb23b4605 | 69 | sp46Axis.attach |
| MasashiNomura | 2:f0fbb23b4605 | 70 | (uartRxIntHndler46AxisS //登録するハンドラ |
| MasashiNomura | 2:f0fbb23b4605 | 71 | ,Serial::RxIrq //割り込み要因 |
| MasashiNomura | 2:f0fbb23b4605 | 72 | ); |
| MasashiNomura | 2:f0fbb23b4605 | 73 | |
| MasashiNomura | 2:f0fbb23b4605 | 74 | sp46Axis.printf("***********\r\n"); |
| MasashiNomura | 2:f0fbb23b4605 | 75 | sp46Axis.printf("UART open!!\r\n"); |
| MasashiNomura | 2:f0fbb23b4605 | 76 | sp46Axis.printf("-----------\r\n"); |
| MasashiNomura | 2:f0fbb23b4605 | 77 | sp46Axis.printf("short = %d\r\n" ,sizeof(unsigned short) ); |
| MasashiNomura | 2:f0fbb23b4605 | 78 | sp46Axis.printf("int = %d\r\n" ,sizeof(unsigned int) ); |
| MasashiNomura | 2:f0fbb23b4605 | 79 | sp46Axis.printf("long = %d\r\n" ,sizeof(unsigned long) ); |
| MasashiNomura | 2:f0fbb23b4605 | 80 | sp46Axis.printf("***********\r\n"); |
| takeru0x1103 | 0:ecd925601fc6 | 81 | } |