Recently, I was trying to use the button to select the specific actions.
Actually, the program is built successfully and it can show the "UART Start!" via serial port, but there was no button response.
Does there has anybody meet the same problem, or I just do the wrong flow in the program? How to fix it?
BTW, the program was developed by SDK11 and based on "uart_pca10028"
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. * * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. * * Licensees are granted free, non-transferable use of the information. NO * WARRANTY of ANY KIND is provided. This heading must NOT be removed from * the file. * */ /** @file * @defgroup uart_example_main main.c * @{ * @ingroup uart_example * @brief UART Example Application main file. * * This file contains the source code for a sample application using UART. * */ /** *@brief this development is for the multiple functions with below: *Function_BUTTON *Function_ADC *Function_VIBRATOR *Function_PWM *please use above symbol to define the function *each time re-define must rebuild the program then load */ #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include "app_uart.h" // serial port display #include "app_error.h" //for UART notify #include "nrf_delay.h" //time delay #include "nrf_gpio.h" //gpio control and setting #include "nrf_gpiote.h" //button control #include "nrf.h" //identify the software /*Below were added for PWM application*/ #include "nrf_drv_timer.h" //include for PWM simulation #include "nrf_drv_ppi.h" //improve the response #include "nrf_drv_gpiote.h" // turns the GPIO staus /*Below were added for button event*/ #include "app_timer.h" #include "app_button.h" #include "app_gpiote.h" #include "bsp.h" //button for functionally module ////////////////////////////////////////////Define/////////////////////////// /*UART definitions*/ //#define ENABLE_LOOPBACK_TEST /**< if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */ #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */ #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */ #define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */ /*Button event definition*/ #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */ #define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) #define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */ ////////////////////////////////////End fo Define/////////////////////////// ////////////////////////////////////////////UART////////////////// /*Wedy add UART control*/ /*baudrate=115200, 8 component(view in the content)*/ void uart_error_handle(app_uart_evt_t * p_event) { if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR) { APP_ERROR_HANDLER(p_event->data.error_communication); } else if (p_event->evt_type == APP_UART_FIFO_ERROR) { APP_ERROR_HANDLER(p_event->data.error_code); } } ////////////////////////////////////////////UART////////////////// ////////////////////////////BSP event control content/////////////////////////// void bsp_event_handler(bsp_event_t event) { switch (event) { case BSP_EVENT_KEY_0: printf("push"); break; case BSP_EVENT_KEY_1: printf("push1"); break; default: break; } } static void buttons_init(void) { uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, BUTTON_DETECTION_DELAY, bsp_event_handler); APP_ERROR_CHECK(err_code); } ////////////////////////////BSP event control content/////////////////////////// /******* ******* ****** ***** *** ** * @brief Function for main application entry. */ int main(void) { /*UART content */ uint32_t err_code; const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud115200 //the baudrate is set }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); /*UART content End*/ //bsp bool erase_bonds; //app_button uses app_timer, if this is not initialize, then initialize it here APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false); buttons_init(); bsp_event_to_button_action_assign(0, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_KEY_0); bsp_event_to_button_action_assign(1, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_KEY_1); printf("\r\nUART Start!\r\n"); for(;;) { } } /** @} */