2 years, 9 months ago.

Trouble with 2 InterruptIn

I'm having trouble when using 2 InterruptIn in the same code while using ublox evk-NINA-B112. I came up with this test code, that I've already tried to compile in other boards, like FRDM-KL25Z and K64, ST Nucleo L152RE, and all worked fine.

I don't know if there's any problem with my code, or if this could be a problem with my board.

I also changed the pins from the Interrupt, made many combinations, tried to use the both switches at the evk-board, but only the first assigned Interrupt works...

2 InterruptIn

#include "mbed.h"

InterruptIn isr_01(D3); 
InterruptIn isr_02(D5); 
//InterruptIn isr_01(D3, PullUp); 
//InterruptIn isr_02(D5, PullUp); 

Serial uart(D1, D0); 

int pino_01 = 0;
int pino_02 = 0;

void subida_01(){ 
    pino_01 = 1;

void descida_01(){ 
    pino_01 = 2;

void subida_02(){ 
    pino_02 = 1;

void descida_02(){ 
    pino_02 = 2;

int main(){



        if(pino_01 == 1){
            uart.printf("subida no pino 1\n");
            pino_01 = 0;
        if(pino_01 == 2){
            uart.printf("descida no pino 1\n");
            pino_01 = 0;
        if(pino_02 == 1){
            uart.printf("subida no pino 2\n");
            pino_02 = 0;
        if(pino_02 == 2){
            uart.printf("descida no pino 2\n");
            pino_02 = 0;
        uart.printf("0,5 sec\n");


Any tips?

Question relating to:

Development board for the u-blox NINA-B1 fully certified Bluetooth low energy module with Arm® Cortex®-M4 with FPU and NFC

2 Answers

2 years, 9 months ago.

If you look at PinNames.h for that target PinNames.h

D5 = NC, // SWDIO

SWDIO of course is one of the programming pins. If you dig into the schematic that pin on J3 is also labeled SWDIO. So I think you are going to need to pick a different pin.

2 years, 8 months ago.

Can you try making one small change to your code:

volatile int pino_01 = 0;
volatile int pino_02 = 0;

Without the volatile keyword the compiler can perform optimizations which mean that if a variable is changed in an interrupt that change may not be seen by the main loop. Volatile prevents it from doing this and forces it to check the actual variable value every time.

Missing out the volatile keyword when it is needed can result in code that works on some platforms and not on others or which stops / starts working due to seemingly unrelated changes in other parts of the code.