ferney alberto beltran molina
/
UART_IRQ
EJEMPLO 4
main.cpp@4:2b238baaf241, 2017-11-16 (annotated)
- Committer:
- fabeltranm
- Date:
- Thu Nov 16 00:37:08 2017 +0000
- Revision:
- 4:2b238baaf241
- Parent:
- 3:6d59b6f1cac0
add BT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:3c37e1389d2a | 1 | #include "mbed.h" |
fabeltranm | 0:3c37e1389d2a | 2 | |
fabeltranm | 0:3c37e1389d2a | 3 | |
fabeltranm | 0:3c37e1389d2a | 4 | Serial device(USBTX, USBRX); // tx, rx |
fabeltranm | 2:69eedc1d4f59 | 5 | |
fabeltranm | 2:69eedc1d4f59 | 6 | Serial deviceBT(D8, D2); // tx, rx |
fabeltranm | 0:3c37e1389d2a | 7 | DigitalOut output1(LED1); // digital output |
fabeltranm | 0:3c37e1389d2a | 8 | |
fabeltranm | 0:3c37e1389d2a | 9 | void Rx_interrupt(); |
fabeltranm | 2:69eedc1d4f59 | 10 | |
fabeltranm | 2:69eedc1d4f59 | 11 | void Rx_interruptBT(); |
fabeltranm | 0:3c37e1389d2a | 12 | |
fabeltranm | 0:3c37e1389d2a | 13 | |
fabeltranm | 0:3c37e1389d2a | 14 | // main test program |
fabeltranm | 0:3c37e1389d2a | 15 | int main() { |
fabeltranm | 0:3c37e1389d2a | 16 | |
fabeltranm | 0:3c37e1389d2a | 17 | device.baud(9600); |
fabeltranm | 2:69eedc1d4f59 | 18 | deviceBT.baud(9600); |
fabeltranm | 0:3c37e1389d2a | 19 | output1=0; |
fabeltranm | 0:3c37e1389d2a | 20 | // Setup a serial interrupt function to receive data |
fabeltranm | 4:2b238baaf241 | 21 | device.attach(&Rx_interrupt, Serial::RxIrq); |
fabeltranm | 4:2b238baaf241 | 22 | deviceBT.attach(&Rx_interruptBT, Serial::RxIrq); |
fabeltranm | 2:69eedc1d4f59 | 23 | while(1) { |
fabeltranm | 0:3c37e1389d2a | 24 | wait_ms(2000); |
fabeltranm | 0:3c37e1389d2a | 25 | |
fabeltranm | 0:3c37e1389d2a | 26 | } |
fabeltranm | 0:3c37e1389d2a | 27 | } |
fabeltranm | 0:3c37e1389d2a | 28 | |
fabeltranm | 0:3c37e1389d2a | 29 | |
fabeltranm | 0:3c37e1389d2a | 30 | // Interupt Routine to read in data from serial port |
fabeltranm | 0:3c37e1389d2a | 31 | void Rx_interrupt() { |
fabeltranm | 1:216bc483f4f3 | 32 | output1=!output1; |
fabeltranm | 1:216bc483f4f3 | 33 | char d = device.getc(); |
fabeltranm | 1:216bc483f4f3 | 34 | device.printf("irq %c\n",d); |
fabeltranm | 1:216bc483f4f3 | 35 | |
fabeltranm | 0:3c37e1389d2a | 36 | return; |
fabeltranm | 0:3c37e1389d2a | 37 | } |
fabeltranm | 2:69eedc1d4f59 | 38 | |
fabeltranm | 2:69eedc1d4f59 | 39 | // Interupt Routine to read in data from serial port |
fabeltranm | 2:69eedc1d4f59 | 40 | void Rx_interruptBT() { |
fabeltranm | 2:69eedc1d4f59 | 41 | output1=!output1; |
fabeltranm | 2:69eedc1d4f59 | 42 | char d = deviceBT.getc(); |
fabeltranm | 3:6d59b6f1cac0 | 43 | deviceBT.printf("irq %c\n",d); |
fabeltranm | 2:69eedc1d4f59 | 44 | |
fabeltranm | 2:69eedc1d4f59 | 45 | return; |
fabeltranm | 2:69eedc1d4f59 | 46 | } |
fabeltranm | 0:3c37e1389d2a | 47 | |
fabeltranm | 0:3c37e1389d2a | 48 | |
fabeltranm | 2:69eedc1d4f59 | 49 | |
fabeltranm | 2:69eedc1d4f59 | 50 | |
fabeltranm | 0:3c37e1389d2a | 51 |