This code is tho put in evidence a BUG in the TIMER implementation on Nordic TIMER bug nRF51822. This Example was created for plateform nRF51-DK. Led 2 will stop blinking (crashed main) when user button is pressed several time. User button start an interrpt, the interrupt set a tickker timer 200ms laterthe change LED 1. Meanwhile in the main loop LED 2 is changing state. You will see taht after a chile LED2 will sotp blinking meaning that program is crashed.
Fork of mbed_blinky by
main.cpp@7:a121fc972b2a, 2014-12-29 (annotated)
- Committer:
- roscop
- Date:
- Mon Dec 29 11:03:29 2014 +0000
- Revision:
- 7:a121fc972b2a
- Parent:
- 4:81cea7a352b0
this code is tho put in evidence a bug in the TIMER implementation on Nordic nRF51822. Example was created for plateform nRF51-DK.; Led 2 will stop blinking (crashed main) when user button 2 is pressed several time.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
roscop | 7:a121fc972b2a | 1 | #include "mbed.h" |
roscop | 7:a121fc972b2a | 2 | |
roscop | 7:a121fc972b2a | 3 | Ticker flipper1; |
roscop | 7:a121fc972b2a | 4 | Timer t1; |
roscop | 7:a121fc972b2a | 5 | |
roscop | 7:a121fc972b2a | 6 | InterruptIn button(p17); |
roscop | 7:a121fc972b2a | 7 | DigitalOut led1(p24); |
roscop | 7:a121fc972b2a | 8 | DigitalOut led2(p23); |
roscop | 7:a121fc972b2a | 9 | |
roscop | 7:a121fc972b2a | 10 | |
roscop | 7:a121fc972b2a | 11 | |
roscop | 7:a121fc972b2a | 12 | void trigger() |
roscop | 7:a121fc972b2a | 13 | { |
roscop | 7:a121fc972b2a | 14 | |
roscop | 7:a121fc972b2a | 15 | t1.reset (); |
roscop | 7:a121fc972b2a | 16 | |
roscop | 7:a121fc972b2a | 17 | led1 = !led1; |
roscop | 7:a121fc972b2a | 18 | |
roscop | 7:a121fc972b2a | 19 | button.enable_irq (); |
roscop | 7:a121fc972b2a | 20 | flipper1.detach(); // the address of the function to be attached (flip) and the interval (2 seconds) |
roscop | 7:a121fc972b2a | 21 | |
roscop | 7:a121fc972b2a | 22 | } |
roscop | 7:a121fc972b2a | 23 | |
roscop | 7:a121fc972b2a | 24 | void interrupt_in() |
roscop | 7:a121fc972b2a | 25 | { |
roscop | 7:a121fc972b2a | 26 | |
roscop | 7:a121fc972b2a | 27 | flipper1.attach_us(&trigger, 200000); // the address of the function to be attached (flip) and the interval (2 seconds) |
roscop | 7:a121fc972b2a | 28 | button.disable_irq (); |
roscop | 7:a121fc972b2a | 29 | } |
roscop | 7:a121fc972b2a | 30 | |
roscop | 7:a121fc972b2a | 31 | int main() |
roscop | 7:a121fc972b2a | 32 | { |
roscop | 7:a121fc972b2a | 33 | button.rise(&interrupt_in); // attach the address of th |
roscop | 7:a121fc972b2a | 34 | t1.start(); |
roscop | 7:a121fc972b2a | 35 | |
roscop | 7:a121fc972b2a | 36 | while(1) { |
roscop | 7:a121fc972b2a | 37 | led2 = !led2; |
roscop | 7:a121fc972b2a | 38 | wait(0.5); |
roscop | 7:a121fc972b2a | 39 | } |
roscop | 7:a121fc972b2a | 40 | } |