A test program to see why the RTOS doesn't like to play with the serial interrupt.

Dependencies:   mbed-rtos mbed

Committer:
the_programmer
Date:
Sun Jan 06 12:28:15 2013 +0000
Revision:
1:54099c52b7dc
Parent:
0:7cdb93589064
Working with serial interrupt and echo to PC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the_programmer 0:7cdb93589064 1 #include "mbed.h"
the_programmer 0:7cdb93589064 2
the_programmer 0:7cdb93589064 3 #define DEBUG
the_programmer 0:7cdb93589064 4
the_programmer 0:7cdb93589064 5 DigitalOut led1(LED1);
the_programmer 0:7cdb93589064 6 DigitalOut led2(LED2);
the_programmer 1:54099c52b7dc 7 DigitalOut led3(LED3);
the_programmer 0:7cdb93589064 8 Serial probe(p9,p10);
the_programmer 0:7cdb93589064 9
the_programmer 0:7cdb93589064 10 #ifdef DEBUG
the_programmer 0:7cdb93589064 11 Serial pc(USBTX,USBRX);
the_programmer 0:7cdb93589064 12 #endif
the_programmer 0:7cdb93589064 13
the_programmer 0:7cdb93589064 14 char serialBuffer[256];
the_programmer 0:7cdb93589064 15 unsigned char serialBufferLoc = 0;
the_programmer 0:7cdb93589064 16
the_programmer 0:7cdb93589064 17 void rxInterrupt(void){
the_programmer 0:7cdb93589064 18 led2=!led2;
the_programmer 1:54099c52b7dc 19 serialBuffer[serialBufferLoc] = LPC_UART3->RBR; //read the input
the_programmer 1:54099c52b7dc 20 //serialBuffer[serialBufferLoc] = probe.getc(); //stops the controller
the_programmer 1:54099c52b7dc 21
the_programmer 1:54099c52b7dc 22 LPC_UART0->RBR = serialBuffer[serialBufferLoc]; //write to the pc
the_programmer 1:54099c52b7dc 23 //pc.putc(serialBuffer[serialBufferLoc]); //stops the controller
the_programmer 1:54099c52b7dc 24
the_programmer 0:7cdb93589064 25 if (serialBuffer[serialBufferLoc] == 0x0A) {
the_programmer 1:54099c52b7dc 26 led3 =! led3;
the_programmer 0:7cdb93589064 27 }
the_programmer 0:7cdb93589064 28
the_programmer 0:7cdb93589064 29 serialBufferLoc++;
the_programmer 0:7cdb93589064 30 }
the_programmer 0:7cdb93589064 31
the_programmer 0:7cdb93589064 32 void serialProbeInit(void){
the_programmer 0:7cdb93589064 33 probe.baud(9600);
the_programmer 0:7cdb93589064 34 probe.format(8,Serial::None,1);
the_programmer 0:7cdb93589064 35 probe.attach(&rxInterrupt,Serial::RxIrq);
the_programmer 0:7cdb93589064 36 }
the_programmer 0:7cdb93589064 37
the_programmer 0:7cdb93589064 38 #ifdef DEBUG
the_programmer 0:7cdb93589064 39 void serialPcInit(void){
the_programmer 0:7cdb93589064 40 pc.baud(115200);
the_programmer 0:7cdb93589064 41 pc.format(8,Serial::None,1);
the_programmer 0:7cdb93589064 42 }
the_programmer 0:7cdb93589064 43 #endif
the_programmer 0:7cdb93589064 44
the_programmer 0:7cdb93589064 45 int main(){
the_programmer 0:7cdb93589064 46 serialProbeInit();
the_programmer 0:7cdb93589064 47 #ifdef DEBUG
the_programmer 0:7cdb93589064 48 serialPcInit();
the_programmer 0:7cdb93589064 49 pc.printf("Comtest, MBED started\r\n");
the_programmer 0:7cdb93589064 50 #endif
the_programmer 0:7cdb93589064 51 while(1){
the_programmer 0:7cdb93589064 52 led1 = 1;
the_programmer 0:7cdb93589064 53 wait(0.2);
the_programmer 0:7cdb93589064 54 led1 = 0;
the_programmer 0:7cdb93589064 55 wait(0.2);
the_programmer 0:7cdb93589064 56 }
the_programmer 0:7cdb93589064 57 }