Hi All! I'm using RTOS and still vainly seeking a solution to the problem with the serial port.
Based on testing of many different variations I've come to the following code:
#include "mbed.h"
#include "rtos.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
Serial pc(USBTX, USBRX);
Thread *RX_THREAD_POINTER;
// Rx Interupt Routine
void Rx_interrupt(void){
uint32_t RBR = LPC_UART0->RBR; // reset RBR interrupt flag
(*RX_THREAD_POINTER).signal_set(0x1); // dereference of RX_THREAD_POINTER
}
// Read received chars from serial port
void rx_thread(void const *argument){
while (true) {
// Signal flags that are reported as event are automatically cleared.
Thread::signal_wait(0x1);
while (pc.readable()) { // Serial port 'pc' is never readable. Why?
led3=!led3; // LED never lights..
pc.putc(pc.getc()); // Input buffer of serial port 'pc' is empty. Why?
}
led2=!led2;
}
}
int main(){
Thread t_rx(rx_thread);
RX_THREAD_POINTER = &t_rx; // Set thread pointer as globally-accessible
t_rx.set_priority(osPriorityHigh);
pc.attach(&Rx_interrupt, RxIrq);
pc.printf("Start\r\n");
while(true){
led1=!led1;
Thread::wait(1000);
}
}
Rx interrupt is generated reliably, but condition "pc.readable()" is never TRUE, and the "pc.getc()" does not return any data.
Why? Where is my mistake?
Please suggest me another solution!
Thank You all! Vladimir
LPC1768, mbed library revision 47, rtos revision 8
Hi All! I'm using RTOS and still vainly seeking a solution to the problem with the serial port.
Based on testing of many different variations I've come to the following code:
Rx interrupt is generated reliably, but condition "pc.readable()" is never TRUE, and the "pc.getc()" does not return any data.
Why? Where is my mistake?
Please suggest me another solution!
Thank You all! Vladimir
LPC1768, mbed library revision 47, rtos revision 8