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

nRF52 Button Characteristic Adding

Hi Everyone,
I am trying to add a characteristic in the BLE_UART project. I'm intending to use that characteristic to transmit the state of a button.
I have copy-pasted the button implementation from the BLE_BLINKY project. My buttons_leds_init() function looks like this : 

static void buttons_leds_init(bool * p_erase_bonds)
{
bsp_event_t startup_event;

uint32_t err_code = bsp_init(LEDBUTTON_BUTTON, button_event_handler);
APP_ERROR_CHECK(err_code);

err_code = bsp_btn_ble_init(NULL, &startup_event);
APP_ERROR_CHECK(err_code);

*p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
}

and the button_event_handler() function is this : 

static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
ret_code_t err_code;

switch (pin_no)
{
case LEDBUTTON_BUTTON:
NRF_LOG_INFO("Send button state change.");
err_code = ble_nus_on_button_change(m_conn_handle, &m_nus, button_action);
if (err_code != NRF_SUCCESS &&
err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
err_code != NRF_ERROR_INVALID_STATE &&
err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
{
APP_ERROR_CHECK(err_code);
}
break;

default:
APP_ERROR_HANDLER(pin_no);
break;
}

Even though i tried to follow the same logic found in the button characteristic of the blinky project i can't seem to notify the central for button state changes and even further after trying to add some breakpoints the button_event_handler is never actually reached. So there is probably something i am missing in the button implementation. Probably some interrupt that happens once the button is pressed but i am unable to find it. So if someone could clarify this matter to me. 
Thanks

Parents
  • Hi,

    err_code = ble_nus_on_button_change(m_conn_handle, &m_nus, button_action);

     You need to register a BLE event observer using the NRF_SDH_BLE_OBSERVER macro. Example:

    ble_lbs_c_t instance;
    NRF_SDH_BLE_OBSERVER(anything, BLE_LBS_C_BLE_OBSERVER_PRIO,
                         ble_lbs_c_on_ble_evt, &instance);
    

    Take a look at ble_lbs.h in the ble_app_blinky example. See here for more documentation of the LED Button Service.

    Regards,

    Marjeris

Reply
  • Hi,

    err_code = ble_nus_on_button_change(m_conn_handle, &m_nus, button_action);

     You need to register a BLE event observer using the NRF_SDH_BLE_OBSERVER macro. Example:

    ble_lbs_c_t instance;
    NRF_SDH_BLE_OBSERVER(anything, BLE_LBS_C_BLE_OBSERVER_PRIO,
                         ble_lbs_c_on_ble_evt, &instance);
    

    Take a look at ble_lbs.h in the ble_app_blinky example. See here for more documentation of the LED Button Service.

    Regards,

    Marjeris

Children
No Data
Related