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.
12 years, 3 months ago.
Problems with serial interrupts?
Hi, I want to use serial interrupts.
If I use this code, it always shows an error:
device.attach(&Rx_interrupt, Serial::RxIrq);
ERROR:
"class "mbed::Serial" has no member "RxIrq"" in file "/main.cpp", Line: 34, Col: 39
I also used this Demo Code: https://mbed.org/cookbook/Serial-Interrupts
but it shows the same error message.
What's wrong with my compiler :D?
1 Answer
12 years, 3 months ago.
Hi Franziska,
as part of the complete refactoring of the mbed library we moved the parameter type definitions from the C++ API to the C API. The missing interrupt enum has moved from Serial.h
to serial_api.h
: serial_api.h
This is a simple example for the new API:
#include "mbed.h" DigitalOut led1(LED1); DigitalOut led2(LED2); Serial computer(USBTX, USBRX); void txCallback() { led1 = !led1; } void rxCallback() { led2 = !led2; computer.putc(computer.getc()); } int main() { printf("start\n"); computer.attach(&txCallback, TxIrq); computer.attach(&rxCallback, RxIrq); while (true) { wait(1); } }
HTH, Emilio
missing of object in attach funaction. Corrected code.
- include "mbed.h"
DigitalOut led1(LED1); DigitalOut led2(LED2);
Serial computer(p9, p10);
void txCallback() { led1 = !led1; }
void rxCallback() { led2 = !led2; computer.putc(computer.getc()); }
int main() { printf("start\n"); computer.attach(&txCallback, computer.TxIrq); computer.attach(&rxCallback, computer.RxIrq); while (true) { wait(1); } }
posted by 14 Feb 2013