2019-07-31 08:28 AM
I'm working with the STM32L152. I have a USB port which has a detect signal connected to an IO pin. When the USB plug is inserted or removed the detect pin changes state. On some occasions the signal is missed. Looking at the signal on the scope shows lots of bouncing (I'm surprised no one's looked at this before). Anyway, I'd like to make the interrupt level triggered instead of edge triggered, which will hopefully deal with the problem. I don't see anything in either the STM32 data sheets or the NVIC data sheet on how to change interrupt modes. Can anyone point me in the right direction? Thanks.
Lee
2019-07-31 11:24 AM
When used as EXTI inputs, GPIO pins can only generate edge triggered interrupts. You are going to have to either add your own software debounce or change your hardware. You could detect an edge, then disable the EXTI interrupt for some debounce interval, sample the input to see what state it is in, then re-enable the EXTI. Another alternative may be to simply poll the pin in your SYSTick interrupt and do software debounce. Or use another timer if you need faster sampling (you shouldn't, not for USB connect/disconnect events). Or, maybe, depending which GPIO pin you are using, there may be an alternate function as an input to a peripheral that you may be able to use to simulate a level sensitive interrupt. Off the top of my head the only one I can think of would be to use the input to gate a timer, and if the timer is enabled to count some number of counts declare the signal "asserted" and then change the input polarity to detect the other transition. Look for "slave mode gated mode" in the timer section of the reference manual.
2019-07-31 12:43 PM
Thanks for the response, Bob. I suspected that level triggering wasn't available. Unfortunately I'm using the EXTI pin to wake up from sleep mode, so polling isn't an option. I'm experimenting with clearing the EXTI interrupts pending register. I'll see how that goes.