ferney alberto beltran molina
/
UART_IRQ
main.cpp@1:216bc483f4f3, 2017-10-28 (annotated)
- Committer:
- fabeltranm
- Date:
- Sat Oct 28 02:44:09 2017 +0000
- Revision:
- 1:216bc483f4f3
- Parent:
- 0:3c37e1389d2a
- Child:
- 2:69eedc1d4f59
irq
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 | 0:3c37e1389d2a | 5 | DigitalOut output1(LED1); // digital output |
fabeltranm | 0:3c37e1389d2a | 6 | |
fabeltranm | 0:3c37e1389d2a | 7 | void Rx_interrupt(); |
fabeltranm | 0:3c37e1389d2a | 8 | void send_line(); |
fabeltranm | 0:3c37e1389d2a | 9 | void read_line(); |
fabeltranm | 0:3c37e1389d2a | 10 | |
fabeltranm | 0:3c37e1389d2a | 11 | |
fabeltranm | 0:3c37e1389d2a | 12 | // main test program |
fabeltranm | 0:3c37e1389d2a | 13 | int main() { |
fabeltranm | 0:3c37e1389d2a | 14 | |
fabeltranm | 0:3c37e1389d2a | 15 | device.baud(9600); |
fabeltranm | 0:3c37e1389d2a | 16 | output1=0; |
fabeltranm | 0:3c37e1389d2a | 17 | // Setup a serial interrupt function to receive data |
fabeltranm | 0:3c37e1389d2a | 18 | device.attach(&Rx_interrupt, Serial::RxIrq); |
fabeltranm | 0:3c37e1389d2a | 19 | while(1) { |
fabeltranm | 0:3c37e1389d2a | 20 | wait_ms(2000); |
fabeltranm | 0:3c37e1389d2a | 21 | |
fabeltranm | 0:3c37e1389d2a | 22 | } |
fabeltranm | 0:3c37e1389d2a | 23 | } |
fabeltranm | 0:3c37e1389d2a | 24 | |
fabeltranm | 0:3c37e1389d2a | 25 | |
fabeltranm | 0:3c37e1389d2a | 26 | // Interupt Routine to read in data from serial port |
fabeltranm | 0:3c37e1389d2a | 27 | void Rx_interrupt() { |
fabeltranm | 1:216bc483f4f3 | 28 | output1=!output1; |
fabeltranm | 1:216bc483f4f3 | 29 | char d = device.getc(); |
fabeltranm | 1:216bc483f4f3 | 30 | device.printf("irq %c\n",d); |
fabeltranm | 1:216bc483f4f3 | 31 | |
fabeltranm | 0:3c37e1389d2a | 32 | return; |
fabeltranm | 0:3c37e1389d2a | 33 | } |
fabeltranm | 0:3c37e1389d2a | 34 | |
fabeltranm | 0:3c37e1389d2a | 35 | |
fabeltranm | 0:3c37e1389d2a | 36 |