Bluepill external interrupts
Posted: Mon Feb 01, 2021 5:35 pm
Hi
I have been trying to program the bluepill with the Arduino IDE using the new core based of HAL. I am having some problems. I am attaching a tactile button to one of the pins, previosly debouncing it with an RC filter. In the software I am setting the Pin as an INPUT_PULLDOWN, since the tactile switch is connected to 3.3v when pressed, and I am setting the interrupt using attachInterrupt(digitalPinToInterrupt(PB4), ISR1, RISING);
I have a simple counter in the interrupt routine that prints the count to the serial port, when the program is started (or reseted) the count is already at around 15. When I press the button the count sums 1 or 2, but when I let go it sums about 15 (even though the interrupt is only set to RISING). I came to figure out that the first 15 that come from the restart actually are because at restart that particular pin is tight high, so when it comes low it triggers the unexpected behaviour that i described with the switch. Looking at the scope for the pin I really can't see any debouncing problems. I am really lost.
Another thing, I was able to get a better behaviour when switching the BOOT0 again after programming, and switching back and forth after restarts, but the results are not consistent, sometimes that method works and sometimes it is just the same (and I don't even know why the BOOT0 pin would have something to do with the execution after booting)
Any ideas?
I have been trying to program the bluepill with the Arduino IDE using the new core based of HAL. I am having some problems. I am attaching a tactile button to one of the pins, previosly debouncing it with an RC filter. In the software I am setting the Pin as an INPUT_PULLDOWN, since the tactile switch is connected to 3.3v when pressed, and I am setting the interrupt using attachInterrupt(digitalPinToInterrupt(PB4), ISR1, RISING);
I have a simple counter in the interrupt routine that prints the count to the serial port, when the program is started (or reseted) the count is already at around 15. When I press the button the count sums 1 or 2, but when I let go it sums about 15 (even though the interrupt is only set to RISING). I came to figure out that the first 15 that come from the restart actually are because at restart that particular pin is tight high, so when it comes low it triggers the unexpected behaviour that i described with the switch. Looking at the scope for the pin I really can't see any debouncing problems. I am really lost.
Another thing, I was able to get a better behaviour when switching the BOOT0 again after programming, and switching back and forth after restarts, but the results are not consistent, sometimes that method works and sometimes it is just the same (and I don't even know why the BOOT0 pin would have something to do with the execution after booting)
Any ideas?