Irq error when trying to initialise 2 ultrasonic sensors

Hi, I’m trying to code a system that uses two HC_SR04 ultrasonic distance sensors and a Nucleo F303RE board.

I’m using this library:
written by @JohnnyK (thankyou!)

code, declaring instances:

 ultrasonic front_USS(FTRIG, FECHO, 100ms, 1s, &f_dist);   
 ultrasonic left_USS(LTRIG, LECHO, 100ms, 1s, &l_dist); ```

The code compiles fine, but when I run it the serial just shows this error:
> ++ MbedOS Error Info ++
> Error Status: 0x80FF0100 Code: 256 Module: 255
> Error Message: Fatal Run-time error
> Location: 0x80058FD
> Error Value: 0x0
> Current Thread: main Id: 0x20001F2C Entry: 0x8006C47 StackSize: 0x1000 StackMem: 0x20000518 SP: 0x2000140C 
> For more info, visit:
> -- MbedOS Error Info --
> InterruptIn error: irq channel conflict

The code runs fine for either of the sensors on their own. but it doesn't like having both decalared at once.
I assume the IRQ channel conflict is to do with having timeouts/interrupts happening for both sensors at once. 

Is there a way to get this code working for multiple ultrasonic sensors?



first of all, the library was not made by me, I did just update of few lines to be compatible with MbedOS 6+ (it is in decription) :slight_smile:

I do no see used pins, but probably…

BR, Jan

Hi Jan,

Thanks for your response, here are the pins I’m using on the Nucleo F303RE:

#define FTRIG D9
#define FECHO D10
#define LTRIG D11
#define LECHO D12

//f_dist() and l_dist() defined here

ultrasonic front_USS(FTRIG, FECHO, 100ms, 1s, &f_dist);
ultrasonic left_USS(LTRIG, LECHO, 100ms, 1s, &l_dist);


On STM32 external interrupts share lines.
All PA_1, PB_1, PC_1 … PG_1 share one single line 1
All PA_2, PB_2, PC_2 … PG_2 share one single line 2
All PA_N, PB_N, PC_2 … PG_N share one single line N
And even EXTI may be shared between lines 5 to 9

So user should only consider using one EXTI per GPIO bank and carefully review selection

from the nucleo pinout: D9-D12 = PC_7, PB_6, PA_7, PA_6

does this mean the error is being caused by using pins ending in the same number (6 and 7)?

Yes, and it could work when you just rotate two wires (also on hardware side ofc :slight_smile: )

#define FTRIG D9
#define FECHO D10
//#define LTRIG D11
//#define LECHO D12
#define LTRIG D12
#define LECHO D11

BR, Jan

1 Like

Thanks I’ll give this a try.

Unfortunately the board has stopped uploading code altogether now, I think I might have broken it trying to power it via external battery :upside_down_face:

Yeah, it is possible, I burned-out on-board voltage regulators of Nucleo-L152RE in the past.

BR, Jan