9 years, 8 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()

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main()


    DTR = 0;

     RS485.attach(&Rx_interrupt, RxIrq);

        // Test (it works)
        pc.printf("SERIAL INTERRUPT\r\n");

while(1) {


2 Answers

9 years, 8 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

Accepted Answer

Just tested the cookbook example from below, with STM32 Nucleo F103RB target, no success.

pc.attach(&callback); // has no effect,

I guess


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 andy mosi 11 Aug 2014
9 years, 1 month 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() {
    while (1) {
        led1 = !led1;

Works fine for me on an LPC1768.

posted by Erik - 04 Jul 2013

Weird. I'm using lpc1768. I tried this exact example and it locks up when it enters the rcx interrupt.

Let me go over it again and I'll post an update.

posted by Kevin Mellott 04 Jul 2013

You are using the latest mbed version? Not that you for example did something with an old project that didn't have the latest version?

posted by Erik - 05 Jul 2013