航空研究会
/
uarttest3
i
main.cpp@0:78f11e7b3aa2, 2018-08-28 (annotated)
- Committer:
- TUATBM
- Date:
- Tue Aug 28 07:37:40 2018 +0000
- Revision:
- 0:78f11e7b3aa2
i
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TUATBM | 0:78f11e7b3aa2 | 1 | #include "mbed.h" |
TUATBM | 0:78f11e7b3aa2 | 2 | #include "Serial.h" |
TUATBM | 0:78f11e7b3aa2 | 3 | |
TUATBM | 0:78f11e7b3aa2 | 4 | /*送信*/ |
TUATBM | 0:78f11e7b3aa2 | 5 | /* |
TUATBM | 0:78f11e7b3aa2 | 6 | Serial usbSerial(PA_9, PA_10); |
TUATBM | 0:78f11e7b3aa2 | 7 | |
TUATBM | 0:78f11e7b3aa2 | 8 | void ISR_Serial_Rx() |
TUATBM | 0:78f11e7b3aa2 | 9 | { |
TUATBM | 0:78f11e7b3aa2 | 10 | // シリアルの受信処理 |
TUATBM | 0:78f11e7b3aa2 | 11 | char data = usbSerial.getc(); |
TUATBM | 0:78f11e7b3aa2 | 12 | } |
TUATBM | 0:78f11e7b3aa2 | 13 | |
TUATBM | 0:78f11e7b3aa2 | 14 | void ISR_Serial_Tx() |
TUATBM | 0:78f11e7b3aa2 | 15 | { |
TUATBM | 0:78f11e7b3aa2 | 16 | // シリアルのs送信処理 |
TUATBM | 0:78f11e7b3aa2 | 17 | usbSerial.attach(NULL, Serial::TxIrq); |
TUATBM | 0:78f11e7b3aa2 | 18 | } |
TUATBM | 0:78f11e7b3aa2 | 19 | |
TUATBM | 0:78f11e7b3aa2 | 20 | int main() |
TUATBM | 0:78f11e7b3aa2 | 21 | { |
TUATBM | 0:78f11e7b3aa2 | 22 | // シリアル通信の速度設定 |
TUATBM | 0:78f11e7b3aa2 | 23 | usbSerial.baud(9600); |
TUATBM | 0:78f11e7b3aa2 | 24 | |
TUATBM | 0:78f11e7b3aa2 | 25 | // シリアル通信受信の割り込みイベント登録 |
TUATBM | 0:78f11e7b3aa2 | 26 | usbSerial.attach(ISR_Serial_Rx, Serial::RxIrq); |
TUATBM | 0:78f11e7b3aa2 | 27 | |
TUATBM | 0:78f11e7b3aa2 | 28 | // シリアル通信のデータ送信 |
TUATBM | 0:78f11e7b3aa2 | 29 | usbSerial.attach(ISR_Serial_Tx, Serial::TxIrq); |
TUATBM | 0:78f11e7b3aa2 | 30 | |
TUATBM | 0:78f11e7b3aa2 | 31 | usbSerial.putc(5); |
TUATBM | 0:78f11e7b3aa2 | 32 | |
TUATBM | 0:78f11e7b3aa2 | 33 | |
TUATBM | 0:78f11e7b3aa2 | 34 | while (1) { |
TUATBM | 0:78f11e7b3aa2 | 35 | // メイン処理 |
TUATBM | 0:78f11e7b3aa2 | 36 | wait(1.0); |
TUATBM | 0:78f11e7b3aa2 | 37 | printf("a\r\n"); |
TUATBM | 0:78f11e7b3aa2 | 38 | } |
TUATBM | 0:78f11e7b3aa2 | 39 | } |
TUATBM | 0:78f11e7b3aa2 | 40 | */ |
TUATBM | 0:78f11e7b3aa2 | 41 | |
TUATBM | 0:78f11e7b3aa2 | 42 | |
TUATBM | 0:78f11e7b3aa2 | 43 | /*受信*/ |
TUATBM | 0:78f11e7b3aa2 | 44 | |
TUATBM | 0:78f11e7b3aa2 | 45 | Serial usbSerial(PA_9,PA_10); |
TUATBM | 0:78f11e7b3aa2 | 46 | Serial MySerial1(USBTX,USBRX); |
TUATBM | 0:78f11e7b3aa2 | 47 | |
TUATBM | 0:78f11e7b3aa2 | 48 | void ISR_Serial_Rx() |
TUATBM | 0:78f11e7b3aa2 | 49 | { |
TUATBM | 0:78f11e7b3aa2 | 50 | // シリアルの受信処理 |
TUATBM | 0:78f11e7b3aa2 | 51 | char data = usbSerial.getc(); |
TUATBM | 0:78f11e7b3aa2 | 52 | usbSerial.putc(data); |
TUATBM | 0:78f11e7b3aa2 | 53 | |
TUATBM | 0:78f11e7b3aa2 | 54 | |
TUATBM | 0:78f11e7b3aa2 | 55 | } |
TUATBM | 0:78f11e7b3aa2 | 56 | |
TUATBM | 0:78f11e7b3aa2 | 57 | int main() |
TUATBM | 0:78f11e7b3aa2 | 58 | { |
TUATBM | 0:78f11e7b3aa2 | 59 | // シリアル通信の速度設定 |
TUATBM | 0:78f11e7b3aa2 | 60 | usbSerial.baud(9600); |
TUATBM | 0:78f11e7b3aa2 | 61 | |
TUATBM | 0:78f11e7b3aa2 | 62 | // シリアル通信受信の割り込みイベント登録 |
TUATBM | 0:78f11e7b3aa2 | 63 | usbSerial.attach(ISR_Serial_Rx, Serial::RxIrq); |
TUATBM | 0:78f11e7b3aa2 | 64 | |
TUATBM | 0:78f11e7b3aa2 | 65 | while (1) { |
TUATBM | 0:78f11e7b3aa2 | 66 | // メイン処理 |
TUATBM | 0:78f11e7b3aa2 | 67 | printf("NOKOLAT\r\n"); |
TUATBM | 0:78f11e7b3aa2 | 68 | wait(1.0); |
TUATBM | 0:78f11e7b3aa2 | 69 | |
TUATBM | 0:78f11e7b3aa2 | 70 | } |
TUATBM | 0:78f11e7b3aa2 | 71 | |
TUATBM | 0:78f11e7b3aa2 | 72 | } |