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, 11 months ago.
Serial Interrupt doesn't work?!
I wrote a program that receives telegrams via an RS485 interface. I've checked with a readable command if there is something to read (so even if a telegram enters). Then it was spent with printf to HyperTerminal.
Now I want to do the same thing with a serial interrupt and read directly from the RS485 and write the characters directly back to HyperTerminal. I wrote this code. But it does not work.
I guess the problem are in this line(?!): RS485.attach (& Rx_interrupt, RxIrq);
Because everything else worked with the command readable. What's the problem?
Please help me. :)
#include "mbed.h"
Serial pc (USBTX,USBRX);
Serial RS485(p26, p25);
DigitalOut DTR (p21);
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void Rx_interrupt()
{
pc.putc(RS485.getc());
return;
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main()
{
RS485.baud(62500);
RS485.format(8,ParityForced1,1);
DTR = 0;
pc.baud(230400);
RS485.attach(&Rx_interrupt, RxIrq);
// Test (it works)
pc.printf("SERIAL INTERRUPT\r\n");
while(1) {
}
}
2 Answers
12 years, 11 months ago.
Hi Franziska, there was a bug in the new serial interrupt handler for the LPC1768, we should have fixed it in the latest mbed library release [Rev 45]: mbed Library Releases
Cheers, Emilio
Just tested the cookbook example from below, with STM32 Nucleo F103RB target, no success.
pc.attach(&callback); // has no effect,
I guess
pc.readable()
is always zero ?
Any help would be greatly appreciated. I.e. if I should hack this, where would I begin looking for error in the vast spaces of mbed-src library ? Is it the TARGET folder uart_api.c ? But then, how does the above Serial pc() get initialized from the target ? Thank you.
posted by 11 Aug 201412 years, 3 months ago.
Seems like its not working again. Even the cookbook interrupt examples don't work.
Just tested the cookbook example:
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Serial pc(USBTX, USBRX);
void callback() {
// Note: you need to actually read from the serial to clear the RX interrupt
printf("%c\n", pc.getc());
led2 = !led2;
}
int main() {
pc.attach(&callback);
while (1) {
led1 = !led1;
wait(0.5);
}
}
Works fine for me on an LPC1768.
posted by 04 Jul 2013