Bluepill external interrupts

Post here first, or if you can't find a relevant section!
Post Reply
matimatil
Posts: 4
Joined: Wed Sep 16, 2020 10:31 pm

Bluepill external interrupts

Post by matimatil »

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?
User avatar
fpiSTM
Posts: 1758
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Bluepill external interrupts

Post by fpiSTM »

Could you share your full example.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Bluepill external interrupts

Post by fredbox »

You probably want to debounce in software rather than hardware.
Tactile switches are very noisy and hard to use with an interrupt pin.

Add this code after loop:

Code: Select all

//poll every millisecond
void HAL_SYSTICK_Callback()
{
  // call switch debounce code from here
}
If you have a good software debounce, you don't need a capacitor across the switch.
See https://hackaday.com/2015/12/10/embed-w ... s-part-ii/ and http://www.ganssle.com/debouncing-pt2.htm for examples.
juwo
Posts: 1
Joined: Wed Feb 03, 2021 4:28 pm

Re: Bluepill external interrupts

Post by juwo »

I have almost the same problem. I wrote an interrupt program based on stm32 F103C8T6. As a button, PB4 cannot be used, but PA2 has no problem.
I thought this was because the JTAG function included PB4 as the Rst Pin.
API "pinF1_DisconnectDebug(PB_4); // disable Serial wire JTAG configuration"is not working

following is my codes:

pinMode(PB4, INPUT_PULLUP);

void setup ()
{
attachInterrupt(PB4, Clear, FALLING);//方向清洗注册
}
void Clear()
{
modepin = 2;
delay(50);
}
Post Reply

Return to “General discussion”