This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bsp_button_is_pressed failed to detect the state

Chip: nRF51422

Board: PCA10028

Firmware: S130_nRF51_2.0.1

void timer_accel_update_handler(void * p_context){
      bool p_state;
  bsp_button_is_pressed(BUTTON_3, &p_state);
  printf("%d",p_state);
  if (p_state == true){
		start_accel_update_flag = true;
      }
}
  

static void on_ble_evt(ble_evt_t * p_ble_evt){
uint32_t err_code;

switch (p_ble_evt->header.evt_id)
        {
    case BLE_GAP_EVT_CONNECTED:
        err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
        APP_ERROR_CHECK(err_code);
        m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
        err_code = app_timer_start(m_timer_accel_update_id, TIMER_INTERVAL_ACCEL_UPDATE, NULL);
        APP_ERROR_CHECK(err_code);
        break;

    case BLE_GAP_EVT_DISCONNECTED:
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
        app_timer_stop(m_timer_accel_update_id);
        break;

    default:
        // No implementation needed.
        break;
}}

After connecting to the BlueTooth, no matter how hard I pressed the button 3, the p_state is aways false and it printed 0 on the UART console.

BUTTON_3 is defined as 19 by pca10028.h.

4/14 update:

static void timers_init(void){

    // Initialize timer module.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    uint32_t err_code;
    err_code = app_timer_create(&m_timer_accel_update_id, APP_TIMER_MODE_REPEATED, timer_accel_update_handler);
    APP_ERROR_CHECK(err_code);
}
  • I defined BSP_SIMPLE in C compiler which affect bsp.h, so the button event didn't initial. Also, I add app_button.c and include app_button.h to avoid the compile error because there were some app_button.h function included by bsp.h #ifndef BSP_SIMPLE.

Related