LCP1114FN28 InterruptIn not working

12 Feb 2014

I have found that InterrupIn is not working for the LPC1114, please see my simple test code below,

#include "mbed.h"

InterruptIn Irq(dp17);
DigitalOut trig(dp14);

void My_IRQ_Handler(void);

SPI device(dp2, dp1, dp6); // mosi, miso, sclk
Serial pc(USBTX, USBRX);

int main() {
    
    device.format(8,1);
    device.frequency(1000000);//Test at 1MHz
    pc.baud(115200);
    Irq.rise(&My_IRQ_Handler);//Call handler if rising edge detected
    trig = 0;//Start value for trigger, all trig values can be reversed for Irq.fall
    printf("Simple InterruptIn test\r\n");
    
    while(1){
       
       wait_ms(500);
       trig = 1;//Trigger an event
    
    }   
}

void My_IRQ_Handler(){
    
    printf("Interrupt handler called\r\n");//Visual sanity check
    
    int response = device.write(0x55);//Dummy write
    wait_ms(10);
    response = device.write(0xAA);//Dummy write
    wait_ms(10);
    trig = 0; //Reset the trigger  
    
}

Can someone look at this?

Dave.

13 Feb 2014

I have now checked all port0 pins, the pins that work are dp1,2 ,4, 5,6,24,25,26,27,28 Pins on port0 that don't work are dp3 undefined, dp23 nRST. Port1 pins I have only checked dp17, dp9 these pins do not work. At the moment I have come to the conclusion that port1 pins are not working with InterruptIn. When I have the time I will check the rest of port1 pins.

EDIT: I have now tested all port1 pins none of them work with InterruptIn. So my conclusion above is correct.

Dave.

17 Feb 2014

As response on http://mbed.org/questions/2574/InterruptIn-usage-with-port-1-pins/, I had another quick look at the mbed-src code, and I think I see what is going wrong. Since I don't have the LPC1114, I cannot test it, but you can :).

Can you remove the mbed lib, and import mbed-src (https://mbed.org/users/mbed_official/code/mbed-src/, which for some reason is put on unlisted and forked to another one, which isn't the latest version anymore, if that one doesn't work, try https://mbed.org/teams/SDK-Development/code/mbed-src/). Then go to the interruptin code (https://mbed.org/teams/SDK-Development/code/mbed-src/file/9655231f5786/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/gpio_irq_api.c): target/hal/NXP/LPC11xxLPC11Cxx/gpio_irq_api.c.

So now the actual problem (I think). Once the interrupt is called, it goes to a common interrupt vector and calculates the bit position, using a cool function that would probably be nice on other targets as well, but at the same time I wonder how that function is supposed to handle multiple interrupts. Anyway, going offtopic, the relevant code:

    // Get index of function table from Mask Interrupt Status register
    channel = numofbits(port_reg->MIS - 1);

So there it calculates the channel number. Nice and all. Minus that it completely ignores which port is calling the interrupt. Yeah it reads the bits from that port, but it doesn't take it into account in the channel number. Since it starts from 0 for port0 that works fine, but for higher ports it is wrong. So change it into:

 // Get index of function table from Mask Interrupt Status register
    channel = numofbits(port_reg->MIS - 1) + (port * 12);

And see if that works :)

17 Feb 2014

Just created a project with the adapted source. I will test it tomorrow morning, because i don't have the hardware with me now. What if this is the cause of the problem? How can the official mbed library be updated in that case?

17 Feb 2014

On the mbed github a pull request can be created. Although in general I don't like to do it if I haven't tested the code myself, this is such a simple change that if you can verify it indeed solves the issue, and port 0 also still works, I can create a pull request.

Generally then within 1-3 days it is accepted and the mbed-src library is updated. The main mbed library is updated once in a while (so bugs are already found in mbed-src, and to keep the main mbed lib a bit more stable), so that takes a bit longer.

18 Feb 2014

Goodmorning Erik,

Just tested the code you suggested and it works fine. Tested it on port 0 and port 1. If you can create a pull request it would be great! My students are using the platform, so it would be nice to know when it is available in the main mbed library. Can I receive a notification if the main-mbed library is updated? Until that time i can give them the suggestion to use the mbed-src in their project.

Thank you very much for the good support and the quick response!

Kind regards, Jan

18 Feb 2014

Hey,

Good, I created a pull request :), so within few days max mbed-src should have it. Meanwhile if your students need it you can also publish your mbed-src with the changes, then they can use that one.

Regarding notification, I don't use them myself, but what I think should work is going to: https://mbed.org/users/mbed_official/code/mbed/, there click follow (if you are logged in).

Erik

18 Feb 2014

FYI mbed-src (https://mbed.org/users/mbed_official/code/mbed-src/) has just been updated. So your students can already use that one. And if you have some time available, can you confirm it indeed works?

Erik

18 Feb 2014

Hello Erik,

Confirmed: fetched the latest source and recompiled and downloaded the program. Both port 0 and port 1 work fine.

Kind regards, Jan

18 Feb 2014

Looks like I missed the party! @Erik, you always amaze me that you can always find the source files, you must know the site well! I only ever find header files and give up.

@Jan, Thanks for testing!

Dave.

18 Feb 2014

And apparantly there were enough bug fixes in to do a new release of the mbed lib: https://mbed.org/users/mbed_official/code/mbed//rev/ed8466a608b4