![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
USART RX Interrupt
main.cpp@0:39c8feff805f, 2017-01-20 (annotated)
- Committer:
- thinkfire
- Date:
- Fri Jan 20 11:47:27 2017 +0000
- Revision:
- 0:39c8feff805f
Generating ADC value and transmitting it to USART. If USART RX interrupt occured It will echo the msg.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thinkfire | 0:39c8feff805f | 1 | #include "mbed.h" |
thinkfire | 0:39c8feff805f | 2 | #include "string.h" |
thinkfire | 0:39c8feff805f | 3 | #include "stdio.h" |
thinkfire | 0:39c8feff805f | 4 | |
thinkfire | 0:39c8feff805f | 5 | DigitalOut led2(LED2); |
thinkfire | 0:39c8feff805f | 6 | DigitalOut led3(LED3); |
thinkfire | 0:39c8feff805f | 7 | |
thinkfire | 0:39c8feff805f | 8 | Serial device(p9, p10); // tx, rx |
thinkfire | 0:39c8feff805f | 9 | char msgPC[20],msgDEV[20]; |
thinkfire | 0:39c8feff805f | 10 | |
thinkfire | 0:39c8feff805f | 11 | void serialRXmon(){ |
thinkfire | 0:39c8feff805f | 12 | char msg1[] = "Your msg-> ",msg[30]; |
thinkfire | 0:39c8feff805f | 13 | msg[0] = '\0'; |
thinkfire | 0:39c8feff805f | 14 | int i=0; |
thinkfire | 0:39c8feff805f | 15 | while(msgDEV[i-1]!=0x0D){ |
thinkfire | 0:39c8feff805f | 16 | msgDEV[i] = device.getc(); |
thinkfire | 0:39c8feff805f | 17 | i++; |
thinkfire | 0:39c8feff805f | 18 | led3 = 1; |
thinkfire | 0:39c8feff805f | 19 | } |
thinkfire | 0:39c8feff805f | 20 | msgDEV[i] = '\0'; |
thinkfire | 0:39c8feff805f | 21 | strcat(msg,msg1); |
thinkfire | 0:39c8feff805f | 22 | strcat(msg,msgDEV); |
thinkfire | 0:39c8feff805f | 23 | device.puts(msg); |
thinkfire | 0:39c8feff805f | 24 | led3 = 0; |
thinkfire | 0:39c8feff805f | 25 | device.getc(); |
thinkfire | 0:39c8feff805f | 26 | } |
thinkfire | 0:39c8feff805f | 27 | |
thinkfire | 0:39c8feff805f | 28 | int main() { |
thinkfire | 0:39c8feff805f | 29 | int adcVal; |
thinkfire | 0:39c8feff805f | 30 | device.attach(&serialRXmon); |
thinkfire | 0:39c8feff805f | 31 | while(1) { |
thinkfire | 0:39c8feff805f | 32 | |
thinkfire | 0:39c8feff805f | 33 | adcVal = rand()%255+1; |
thinkfire | 0:39c8feff805f | 34 | |
thinkfire | 0:39c8feff805f | 35 | sprintf(msgPC,"adcVal -> %d\n",adcVal); |
thinkfire | 0:39c8feff805f | 36 | |
thinkfire | 0:39c8feff805f | 37 | if(device.writeable()) { |
thinkfire | 0:39c8feff805f | 38 | device.puts(msgPC); |
thinkfire | 0:39c8feff805f | 39 | } |
thinkfire | 0:39c8feff805f | 40 | led2 = 1; |
thinkfire | 0:39c8feff805f | 41 | wait(1); |
thinkfire | 0:39c8feff805f | 42 | led2 = 0; |
thinkfire | 0:39c8feff805f | 43 | wait(1); |
thinkfire | 0:39c8feff805f | 44 | } |
thinkfire | 0:39c8feff805f | 45 | |
thinkfire | 0:39c8feff805f | 46 | } |
thinkfire | 0:39c8feff805f | 47 |