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.
5 years, 7 months ago.
intercept RESET with my own routnine
Hello world,
I need to intercept the RESET handler in order to make RESET also work as Power-ON/OFF ans BLE Pair depending on the button press length. I am working on nRF52(832).
Is there any "weak" function I could overwrite here to catch the reset event and make something in my code?
I found `NVIC_SystemReset()` but that seems target specific? I found `mbed_reset()` but with no luck to overwrite it..
Maybe I should change the configuration of RESET pin to `InterruptIn()` and then handle events?
Any hints appreciated :-)
2 Answers
5 years, 7 months ago.
Yes NVIC_SystemReset() is target specific and will perform correct steps and flip right register bits to reset the micro from software. This is core functionality, I would not modify it. You often need to call NVIC_SystemReset() inside HardFault handlers to restart after a fault.
So you want an external momentary push button that can both power off the micro and pair BLE? Truly power off micro requires actually disconnecting power from the (presumably) battery. It may be possible to do this but would require some tricky external circuitry which would handle the button rather than the micro. The type of circuit you would be looking for might be called a push button latch circuit.
To truly remove power a slide switch is probably the easiest approach, but that is then 2 buttons instead of one.
For a single button, the simplest approach is probably to put the micro to sleep rather than power it off completely. You won’t be able to use the micro reset pin for this. That pin’s sole function is to restart the micro. The reset button on the devboard is connected to this pin.
For sleep, you will need to use a push button connected to a regular GPIO. The logic would be in normal run mode you use software to monitor long vs short button presses. If sleep/poweroff is requested, then you would enable wake from interrupt on that pin and put the micro to sleep. If BLE pairing is requested obviously you just do that.
5 years, 7 months ago.
I've used the following as a combination reset/reconfigure a device.
Requirements:
- Normal power-on resets the micro
- A quick-press on the push button resets the micro
- A long-press on the push button resets the micro and the switch can be read. My instructions were to press-hold for 5 seconds (even though the SW read the pin in under 1 second, but that may depend on your startup procedure and how long it is).
Simplified into ASCII art:
Vcc Vcc Vcc | | | < 10K < 10K --- Diode > > /_\ | 1uF | | | | O---------+------| (---------+----------+---| !Reset | | | | | O +------------------)--------------| Input Pin | | | | --- 0.1uF | --- | | Gnd Gnd
I don't recall the values, so you'll have to do some simulation (by hand or with LTSpice).
At normal power-up, the 10K on the right, and the 0.1uF, control the power-on reset duration to the micro.
Soon after reset your software can read the Input Pin, to determine if the cause of reset was a normal power up (Input Pin = high), or operator intervention (Input Pin = low).
The values of the 2 caps (and the resistor on the right are designed to ensure that the AC coupled push button can drive the Reset pin low long enough to be valid.
The diode is a protection element - when you hold the button, the 1uF charges. When you release the button it would try to drive the reset pin above Vcc. It is current limited by the resistors, so the diode might not be necessary.
NOTE: Compare this to your PCs behavior, where a quick-press often is the power-sleep toggle, and only a very long press causes full reset.