7 years, 5 months ago.

can't do Interrupt in mbed os

i found that in mbed NVIC_EnableIRQ(UART3_IRQn); is this ( i use LPC4088)

but webpage compiler in mbed os it doesn't work. not definition found matching UART3_IRQn how should i change? /media/uploads/david8251/74.png

Thx very much!!!

#include "mbed.h"


Serial Mod(p9, p10);
Serial Uart3(USBTX,USBRX);//tx, rx

int command[8]={0x08, 0x03, 0x00, 0x01, 0x00, 0x02,0x95,0x52};
char receice[8]={0};
int result;
int i ;
volatile bool PrintFlag = 0;

void Rx_interrupt();

int main()
{

    Uart3.format(8, Serial::None, 1);
    Uart3.baud(9600);
    NVIC_EnableIRQ(UART3_IRQn);
    Mod.attach(&Rx_interrupt, Serial::RxIrq);


        for (int i=0; i<8; i++) {
            while(1)
            {
            if (Mod.writeable())
            {
            result=Mod.putc(command[i]);
            //Uart3.printf("%X",result);
            break;
                }
            }
        }
        while(1){
        if(PrintFlag && Uart3.writeable())
        {
            Uart3.printf("%d\r\n", receice[3]);
            Uart3.printf("%d\r\n", receice[4]);
            PrintFlag = 0;
        }


        }
}

void Rx_interrupt()
{
    static int i =0;
    if (Mod.readable())
    {
        receice[i++]= Mod.getc();
    }
    if(i>6)
    {
        PrintFlag = 1;
        i = 0;

    }
}
posted by jajn HA 12 Nov 2016

This is my code

posted by jajn HA 12 Nov 2016

3 Answers

7 years, 5 months ago.

It compiles... on my computer...

Do you have the message?(not definition found matching UART3_IRQn) it can pass compile but it can't recognize the UART3_IRQn

posted by jajn HA 13 Nov 2016
7 years, 5 months ago.

It seems as though you want a serial interrupt for both "Mod" and "Uart3"? Your code is correct for one interrupt, just do the same for the other. This is correct:

    Mod.attach(&Rx_interrupt, Serial::RxIrq);

Just do the same for Uart3

    //NVIC_EnableIRQ(UART3_IRQn); //No, use the "attach" method
    Uart3.attach(&Rx_interruptOther, Serial::RxIrq);
...
void Rx_interruptOther()
{
...
}

Thx for your answer! But it doesn't work. it can compiler. The same code i can work in LPCXpresso. But can't work on webpage.

posted by jajn HA 15 Nov 2016
7 years, 5 months ago.

There is no compile error when I create a new program with your test code. I guess you are not using latest version of the mbed library and need to update it.

To update mbed library in your project, right click mbed icon in your project and select [update...] from menu list.

Thx~~~ I will try later!!!!

posted by jajn HA 15 Nov 2016