This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

button_event_handler not working properly?

  • Custom Board which has NordicSemi nRF51822-QFAA (QFAAH0, Rev. 3) MCU,

The board follows the internal LDO setup.

(Ref. nRF51822_PS v3.1 Section 11.3.1)

I added LED and button initializing codes.

  • IAR for ARM 7.1

  • Testing with iPhone 5S, 6 and iPad air (iOS 8.3)

    / Nexus 5 and Galaxy Note 3 (Android 4.4.2).

  • Using J-Link Debugger

/****************************************************/

The scheduler, timers, and BLE settings are all fine.

My problem is that the button init doesn't work properly.

buttons

I modified the code in order to divide into files. I don't use the bsp functions.

before

It seems okay at here. However, after calling any functions,

(in this example, after calling timers_start) the mp_buttons become corrupted.

(calling leds_ok didn't changed mp_buttons.)

after

So, when I press the button,

it does call detection_delay_timeout_handler in app_button.c

However, it doesn't jumps to the button_event_handler.

call

Other parts works well. (The timer interrupts, hrs handling, beacon advertising, and etc.)

What could be the reason for the mp_buttons to become corrupted?

What settings did I missed?

The compiler optimization level is "low".

Also, I use the scheduler.

I also tried the bsp_init. Although the event handler function pointer was set to null

err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                    APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                    NULL);

in this case, the values of mp_buttons didn't change when the program counter changes.

Plus, when a button is pressed, the program jumps to bsp_button_event_handler.

static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action)

(Although, it doesn't call any functions since the parameter was NULL)

When the program counter comes here, the values of mp_buttons were valid as I configured.

-Regards

  • Holy cow, I made a terrible mistake. Sorry T.T.

    The problem occurred due to the pointer reference of mp_buttons.

    Stack setting

    This was the default setting of the Stack size.

    Sit 1

    == Situation : if buttons[] is local variable ==

    (I divided source codes into several .c files.

    The main function and buttons_init function is located at different .c files.)

    After the buttons_init function was called, mp_buttons were set.

    mp_button

    As you see, mp_button is referencing memory 0x20003168.

    However, as I wrote at the question, after calling any functions, this value changes.

    Overwrite

    At the CStack, the location of 0x20003168 is now changed

    because I declared the buttons[] as a local variable and now it has different values. (D'oh!!)

    CStack

    app_buttons

    I didn't thought that mp_buttons will use referencing.

    I just guessed (without looking the code...)

    app_button_init will call memcpy or etc to copy the values.

    So the problem is solved by declaring the buttons[] as a static variable or global variable.

    Sorry for this mess... I should have thought more.

    -Regards

Related