6 years, 2 months ago.

Mbed Interrupts

Is there some place where the list of interrupt sources can be found? I know about the digital InterruptIn, but is this all there is?

I understand that Ticker can produce an interrupt like process, but I'm not sure it's an actual interrupt.

Also, is there some procvess to clear an interrupt flag to prevent the interrupt from being processed if it's no longer needed? I know the flag will not be cleared until the interrupt is processed, but if it is pending and I want to clear the flag within a previously entered interrupt, is there a way to do that?

1 Answer

6 years, 2 months ago.

Most IO interfaces can generate interrupts e.g. you can set the system to generate an interrupt when data is received on a serial port.

Tickers and Timeouts are true interrupts.

If you want to disable an IO or Ticker type interrupt that you have previously used in your code then set the interrupt up again but instead of giving a function to call give it a null pointer.

You can also disable all interrupts or individual ones if you wish to. Generally this is only used for a short period while you are doing something you don't want to be interrupted e.g. often a serial port interrupt will get the new data and store it in a buffer, once a full message is received it will set a flag. In the background loop the code will see that flag and make a copy of the buffer and then process the received message. In that situation you would disable the serial interrupt while copying the buffer so that it can't change while the copy is made.

Also all interrupts default to being equal priority. If a timer triggers while handling a serial port interrupt it will wait until the serial interrupt finishes. You can change the priorities if needed e.g. if you had a timer that needs to be very consistent you would make it higher priority so that it could interrupt other interrupts.

Ok, I looked around and found NVIC_SetPriority(EINT3_IRQn, 3); and used it to, I assuem, change the interrupt priority of EINT3 to priority 3. Not sure what I did with this. What pin is EINT3 attached to?

If there is a way to pull out the EINT3 interrupt (I assume this is the external int #3 - I am proficient at programming pic microcontrollers and that'ts what it would mean in that realm) is it possible to get to the others? If so, what others are there? I don't assume I can get them all, but maybe a few more.

Where is information like this documented? The handbook does not have this much detail.

posted by Mity Eltu 20 Sep 2018

Since the interrupts are a little different in each processor it's hard for the API to give that level of control in a simple and consistent way beyond enabling and disabling them all.

Ultimately the information is documented in the Mbed library source code and the user manual for the processor.

If you look at https://os.mbed.com/users/mbed_official/code/mbed-dev/file/0387e8f68319/targets/TARGET_NXP/TARGET_LPC176X/device/LPC17xx.h/ from around line 40 you will see a list of all the different interrupts for the LPC17xx family of parts.

EINT3 is external interrupt 3 which I believe is any GPIO interrupt from pins in IO bank 3 but check the user manual for he processor if you want to be sure.

Also just in case you were't aware, interrupt priorities are such that lower numbers take priority. From memory the mbed default is 3 for everything.

I'm not sure what you mean by "pull out" an interrupt. As indicated before if you want to stop an interrupt then set the function that's called to null, the libraries will take that as a disable.

posted by Andy A 21 Sep 2018

Andy, Thank you for all the help.

What I meant by "pull out" the interrupt is this: On a pic microcontroller, each external interrupt (on most 8-bit controllers) is associated with a particular pin and cannot be assigned to a different one. If I want to use that interrupt, I have to connect to that pin. I am currently using the LPC1768 mbed which brings out 40 total pins to the bread board, but the chip itself has 100 pins. So, I cannot, though the breadboard, gain access to all 100 pins. If the EINT3 interrupt is associated with a pin that is inaccessible though the 40 pins on the mbed, is there a way to associate the interupt with one of the pins I DO have access to? In other words can I assign EINT3 to, say, p5 on the mbed platform?

Are all the interrupts listed in the .h file you mentioned available to me on the mbed platform? How do gain control over these interrupts?

This is a little frustrating to me because of my experience with the pics. I have access to all interrupts on those chips and can manipulate the timers, counters, dac, adc, comparators etc. directly.

posted by Mity Eltu 21 Sep 2018

I think you're overthinking it a little.

On the LPC1768 all of the pins that can be used for general IO other than p19 and p20 can be used as interrupts at the same time.

A lot IO pins share the same CPU interrupt but the libraries then query a separate register to determine which IO pin caused the interrupt and calls the correct function.

Think of a bank of IO pins as any other peripheral. The CPU doesn't have a UART1 Rx interrupt, a UART1 Tx interrupt, a UART1 overflow interrupt etc... It has a single UART1 interrupt, the software then queries the status register of the UART to determine what caused the interrupt. For the IO pins any number of them can cause the same interrupt but it's easy to determine which one it was.

And just as the libraries allow you to set separate UART Tx and Rx interrupts and automatically handle calling the correct user function for you they do the same for each IO pin. You don't need to worry about which CPU interrupt a pin will trigger, the libraries worry about that for you. The only down side to this is that you can't set different priorities for each pin without modifying or bypassing the mbed libraries.

p19 and p20 can't be used because they are connected to GPIO bank 2 of the processor, for some reason on the LPC1768 only IO banks 0,1 and 3 can generate interrupts not bank 2.

And if you really want there is nothing stopping you from accessing the hardware directly just as you are used to on a PIC. The user manual for the processor is available, the libraries even #define a set of constants for all of the different register names.

The issue is that then your code isn't very portable, the whole point of the mbed libraries is that it hides the platform specific implementation details like which CPU IRQ number a particular pin triggers. That way code is far more portable between boards and processors.

The down side is that platform specific features are not always available. A few times I've had to resort to direct register manipulation in order to get the features or performance I need but that's very rare. I've certainly never needed to do that for GPIO interrupts.

posted by Andy A 24 Sep 2018