Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 8 months ago.
MODSERIAL - RX Interrupt
Hello,
I have this simple code and I would like to use MODSERIAL RX Interrupt. When I start up my board, RX Interrupt does not work and i do not know why. Could You help me ?
#include "mbed.h" #include "USBSerial.h" #include "MODSERIAL.h" #include "at25sf041.h" #include "string" //#include "rtos.h" string a; DigitalOut LedStatus(P0_13); DigitalOut LedBattery(P0_14); DigitalOut USB_connect(P0_6); AnalogIn ain(P0_11); USBSerial usb(0x1f00, 0x2012, 0x0001, false); DigitalIn Vbus(P0_3); AT25SF041 memory(P0_9, P0_8, P0_10, P0_15); MODSERIAL uart(P0_19, P0_18); InterruptIn GPS_fix(P0_17); volatile bool newline_detected = false; char tmp[10]; void Rx_interrupt(MODSERIAL_IRQ_INFO *q) { MODSERIAL *serial = q->serial; if ( serial->rxGetLastChar() == '\n') { newline_detected = true; } LedBattery = !LedBattery; } void toogle() { LedStatus = !LedStatus; } void usb_rx() { LedStatus = !LedStatus; //tmp = usb.getc(); LedStatus = !LedStatus; } int main() { USB_connect = 0; GPS_fix.rise(&toogle); uart.baud(9600); uart.attach(&Rx_interrupt, MODSERIAL::RxIrq); while (1) { // if (usb.readable()) //{ // LedStatus = !LedStatus; // tmp = usb.getc(); // } // if (usb.readable()){ // usb.scanf("%s", a); // usb.printf("%s", a); // } if (a == "l0" && newline_detected) { newline_detected = false; char c; while((c = uart.getc()) != '\n') { usb.putc(c); } usb.printf("\r\n"); } } }
So LedBattery does not toggle? Are you sure actual data arrives on that serial connection?
posted by Erik - 22 Mar 2017LedBattery toggle only once. When I remove the condition a=="10" then the code works. There is GPS module on that UART and data arrives every one second.
posted by Peter Augustin 22 Mar 2017Hello, Probably I found out problem. The problem is RX buffer because if RX buffer is full then interrupt is stopped. How can I clean RX buffer ?
posted by Peter Augustin 23 Mar 2017