Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 5 months ago.
It looks like PA_12 can't be an Interrupt IN
Every thing is in the title... It's written that all pins can be InterruptIn but test on PA_12 are showing the exact opposite !
How to be ripped off
Serial Pc (PA_2, PA_3, 460800); DigitalOut Trig1 (PC_3); DigitalOut Trig2 (PC_2); DigitalOut Trig3 (PA_9); DigitalOut Led1 (PA_5); DigitalOut Led2 (PD_2); InterruptIn Echo1 (PA_12); InterruptIn Echo2 (PA_11); InterruptIn Echo3 (PB_12); Ticker timer; Timer temps; int FlagUS1 = 0, FlagUS2 = 0, FlagUS3 = 0; long Echo1Start, Echo2Start, Echo3Start; double DistUS1, DistUS2, DistUS3; void echo1Rise () { Echo1Start = temps.read_us(); } void echo2Rise () { Echo2Start = temps.read_us(); Led2 = !Led2; } void echo3Rise () { Echo3Start = temps.read_us(); } void echo1Fall () { DistUS1 = (double)(temps.read_us() - Echo1Start)/5.8; FlagUS1 = 1; } void echo2Fall () { DistUS2 = (double)(temps.read_us() - Echo2Start)/5.8; FlagUS2 = 1; } void echo3Fall () { DistUS3 = (double)(temps.read_us() - Echo3Start)/5.8; FlagUS3 = 1; } void tickTime() { Tick++; FlagTick = 1; if ((Tick%100)==0) FlagTickLed = 1; } int main() { temps.reset(); temps.start(); timer.attach(&tickTime, 0.001); Echo1.rise (&echo1Rise); Echo2.rise (&echo2Rise); Echo3.rise (&echo3Rise); Echo1.fall (&echo1Fall); Echo2.fall (&echo2Fall); Echo3.fall (&echo3Fall); Echo1.enable_irq(); Echo2.enable_irq(); Echo3.enable_irq(); Led2 = 0; Led1 = 0; while (1) { do { if (FlagTickLed) { Led1 = !Led1; FlagTickLed = 0; } // Gestion des US if (((Tick%150)==0) && FlagTick) { Trig1 = 1; wait_us(15); Trig1 = 0; FlagTick = 0; } if (((Tick%150)==50) && FlagTick) { Trig2 = 1; wait_us(15); Trig2 = 0; FlagTick = 0; } if (((Tick%150)==100) && FlagTick) { Trig3 = 1; wait_us(15); Trig3 = 0; FlagTick = 0; } if (FlagUS1==1) { Pc.printf ("\rUS 1 = %04d mm", (int)DistUS1); FlagUS1 = 0; } if (FlagUS2==1) { Pc.printf ("\r\t\t\tUS 2 = %04d mm", (int)DistUS2); FlagUS2 = 0; } if (FlagUS3==1) { Pc.printf ("\r\t\t\t\t\t\tUS 3 = %04d mm", (int)DistUS3); FlagUS3 = 0; } } while(!Pc.readable()); } }
Does Anyone experience the same problem ?
Question relating to:
1 Answer
7 years, 5 months ago.
If you look at the datasheet you'll see that PA_12 *can* in fact be an interrupt in. However it also states that only *one* source per numeric-input can be provided to the interrupt-input multiplexer. The problem you are having is that you created an instance of InterruptIn Echo3(PB_12). This will cause the initializer to switch the 12th source interrupt input over to PB_12. Try commenting out Echo3 and see if Echo1 starts working. Then you will need to find an appropriate available input on a different numeric input for Echo3.
In other words: PA_12 or PB_12 or PC_12 or PD_12 (etc..) can be the 12th external interrupt source. But only *one* of those inputs! Choose another numeric input for the next interrupt etc..