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

which changes are require in code when use of wakeup button ?

Respected sir, 

There is added external reset button at SRU532 module, and changes are given according to it using wakeup button at code.When wakeup button is used then some part is uncommented and want to reset only one pin using one button of nRF51422.It is done for reset time of BLE advertising after 3 min or within 1 hr,but it is not worked.How it will solve?

...

  • Hi,

    Please refer for instance to the \examples\ble_peripheral\ble_app_hids_keyboard on how to achieve this:

    [...]
    
    uint32_t bsp_btn_ble_sleep_mode_prepare(void)
    {
        uint32_t err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP); 
        RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);
    
        err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP_BOND_DELETE); 
        RETURN_ON_ERROR_NOT_NOT_SUPPORTED(err_code);
        
        return NRF_SUCCESS;
    }
    
    [...]
    
    static void sleep_mode_enter(void)
    {
        uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
    
        APP_ERROR_CHECK(err_code);
    
        // Prepare wakeup buttons.
        err_code = bsp_btn_ble_sleep_mode_prepare();
        APP_ERROR_CHECK(err_code);
    
        // Go to system-off mode (this function will not return; wakeup will cause a reset).
        err_code = sd_power_system_off();
        APP_ERROR_CHECK(err_code);
    }
    
    [...]
    
    sleep_mode_enter();
    while(1);
    
    [...]

  • Thanks for it.I want one button used for reset BLE advertising time which is by default 180 sec in given code.Here used SRU532 module,SDK 9.0 and softdevice s310 for nRF51422.How one pin of SRU532 module is configured from software as well as hardware side?

    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nordic_common.h"
    #include "nrf.h"
    #include "app_error.h"
    #include "nrf_gpio.h"
    #include "nrf51_bitfields.h"
    #include "ble.h"
    #include "ble_hci.h"
    #include "ble_srv_common.h"
    #include "ble_advdata.h"
    #include "ble_hrs.h"
    #include "ble_dis.h"
    #include "ble_conn_params.h"
    #include "ble_nus.h"
    #include "boards.h"
    #include "sensorsim.h"
    #include "softdevice_handler.h"
    #include "app_timer.h"
    #include "device_manager.h"
    #include "ant_parameters.h"
    #include "ant_interface.h"
    #include "pstorage.h"
    #include "app_trace.h"
    #include "bsp.h"
    #include "ant_error.h"
    #include "ant_stack_config.h"
    #include "ant_stack_handler_types.h"
    
    
    
    
    //#include "nrf_drv_rtc.h"
    //#include "nrf_drv_clock.h"
    
    
    
    
    
    #define WAKEUP_BUTTON_ID               	0                                            /**< Button used to wake up the application. */
    #define BOND_DELETE_ALL_BUTTON_ID       1                                            /**< Button used for deleting all bonded centrals during startup. */
    
    #define DEVICE_NAME                     "Nordic_UART"                               /**< Name of device. Will be included in the advertising data. */
    
    //#define DEVICE_NAME                     "nrf51422_HRM"                               /**< Name of device. Will be included in the advertising data. */
    #define MANUFACTURER_NAME               "NordicSemiconductor"                        /**< Manufacturer. Will be passed to Device Information Service. */
    #define APP_ADV_INTERVAL                40                                           /**< The advertising interval (in units of 0.625 ms. This value corresponds to 25 ms). */
    #define APP_ADV_TIMEOUT_IN_SECONDS      3600                                          /**< The advertising timeout in units of seconds. */
    #define NUS_SERVICE_UUID_TYPE           BLE_UUID_TYPE_VENDOR_BEGIN                  /**< UUID type for the Nordic UART Service (vendor specific). */
    
    #define IS_SRVC_CHANGED_CHARACT_PRESENT 0                                            /**< Whether or not to include the service_changed characteristic. If not enabled, the server's database cannot be changed for the lifetime of the device */
    #define APP_TIMER_PRESCALER             0                                            /**< Value of the RTC1 PRESCALER register. */
    //#define APP_TIMER_MAX_TIMERS            (2 + BSP_APP_TIMERS_NUMBER)                  /**< Maximum number of simultaneously created timers. */
    #define APP_TIMER_MAX_TIMERS            	(4 + BSP_APP_TIMERS_NUMBER)                  /**< Maximum number of simultaneously created timers. */
    #define APP_TIMER_OP_QUEUE_SIZE         	4                                            /**< Size of timer operation queues. */
    
    #define MOTOR_DATA_MEAS_INTERVAL          APP_TIMER_TICKS(500, APP_TIMER_PRESCALER) /**< MOTOR data measurement interval (ticks). */
    //#define TS_DATA_MEAS_INTERVAL             APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) /**< Torque sensor data measurement interval (ticks). */
    
    #define SECOND_1_25_MS_UNITS            800                                          /**< Definition of 1 second, when 1 unit is 1.25 ms. */
    #define SECOND_10_MS_UNITS              100                                          /**< Definition of 1 second, when 1 unit is 10 ms. */
    #define MIN_CONN_INTERVAL               (SECOND_1_25_MS_UNITS / 2)                   /**< Minimum acceptable connection interval (0.5 seconds), Connection interval uses 1.25 ms units. */
    #define MAX_CONN_INTERVAL               (SECOND_1_25_MS_UNITS)                       /**< Maximum acceptable connection interval (1 second), Connection interval uses 1.25 ms units. */
    #define SLAVE_LATENCY                   0                                            /**< Slave latency. */
    #define CONN_SUP_TIMEOUT                (4 * SECOND_10_MS_UNITS)                     /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
    
    #define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000, APP_TIMER_PRESCALER)   /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
    #define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000, APP_TIMER_PRESCALER)  /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
    #define MAX_CONN_PARAMS_UPDATE_COUNT    3                                            /**< Number of attempts before giving up the connection parameter negotiation. */
    
    #define SEC_PARAM_TIMEOUT               30                                           /**< Timeout for Pairing Request or Security Request (in seconds). */
    #define SEC_PARAM_BOND                  1                                            /**< Perform bonding. */
    #define SEC_PARAM_MITM                  0                                            /**< Man In The Middle protection not required. */
    #define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE                         /**< No I/O capabilities. */
    #define SEC_PARAM_OOB                   0                                            /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE          7                                            /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE          16                                           /**< Maximum encryption key size. */
    
    #define DEAD_BEEF                       0xDEADBEEF                                   /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
    

    #define BOND_DELETE_ALL_BUTTON_ID, It is require when wakeup button in use?

    uint32_t bsp_buttons_enable()
    {
    #if (BUTTONS_NUMBER > 0) && !defined(BSP_SIMPLE)
        return app_button_enable();
    #else
        return NRF_ERROR_NOT_SUPPORTED;
    #endif
    }
    
    uint32_t bsp_buttons_disable()
    {
    #if (BUTTONS_NUMBER > 0) && !defined(BSP_SIMPLE)
        return app_button_disable();
    #else
        return NRF_ERROR_NOT_SUPPORTED;
    #endif
    }
    
    uint32_t bsp_wakeup_buttons_set(uint32_t wakeup_buttons)
    {
    #if (BUTTONS_NUMBER > 0) && !defined(BSP_SIMPLE)
        for (uint32_t i = 0; i < BUTTONS_NUMBER; i++)
        {
            uint32_t new_cnf = NRF_GPIO->PIN_CNF[m_buttons_list[i]];
            uint32_t new_sense = ((1 << i) & wakeup_buttons) ? GPIO_PIN_CNF_SENSE_Low : GPIO_PIN_CNF_SENSE_Disabled;
            new_cnf &= ~GPIO_PIN_CNF_SENSE_Msk;
            new_cnf |= (new_sense << GPIO_PIN_CNF_SENSE_Pos);
            NRF_GPIO->PIN_CNF[m_buttons_list[i]] = new_cnf;
        }
        return NRF_SUCCESS;
    #else
        return NRF_ERROR_NOT_SUPPORTED;
    #endif

    There is need of change in bsp.c file?

    #define BUTTONS_NUMBER 4
    
    //IO board pull-up buttons
    /*#define BUTTON_A     23 //BUTTON A on N5 Starter Kit IO Board
    #define BUTTON_B     2  //BUTTON B on N5 Starter Kit IO Board
    #define BUTTON_C     12 //BUTTON C on N5 Starter Kit IO Board
    #define BUTTON_D     11 //BUTTON D on N5 Starter Kit IO Board
    #define BUTTON_PULL  NRF_GPIO_PIN_PULLUP*/
    
    //SRU532 board pull-up buttons
    #define BUTTON_A     23 //BUTTON A on N5 Starter Kit IO Board
    #define BUTTON_B     2  //BUTTON B on N5 Starter Kit IO Board
    #define BUTTON_C     30 //BUTTON C on N5 Starter Kit IO Board
    #define BUTTON_D     10 //BUTTON D on N5 Starter Kit IO Board
    #define BUTTON_PULL  NRF_GPIO_PIN_PULLUP
    
    
    
    
    #define BSP_BUTTON_0   BUTTON_A
    #define BSP_BUTTON_1   BUTTON_B
    #define BSP_BUTTON_2   BUTTON_C
    #define BSP_BUTTON_3   BUTTON_D
    
    #define BSP_BUTTON_0_MASK (1<<BSP_BUTTON_0)
    #define BSP_BUTTON_1_MASK (1<<BSP_BUTTON_1)
    #define BSP_BUTTON_2_MASK (1<<BSP_BUTTON_2)
    #define BSP_BUTTON_3_MASK (1<<BSP_BUTTON_3)
    
    #define BUTTONS_MASK   0x00801804 // b100000000001100000000100
    #define BUTTONS_LIST { BUTTON_A, BUTTON_B, BUTTON_C, BUTTON_D }
    
    //Battery board pull-up switches
    #define SWITCH_1     5  // Switch 1 on N5 Starter Kit Battery Board
    #define SWITCH_2     0  // Switch 2 on N5 Starter Kit Battery Board
    #define SWITCH_3     6  // Switch 3 on N5 Starter Kit Battery Board
    #define SWITCH_4     24 // Switch 4 on N5 Starter Kit Battery Board
    #define SWITCH_5     9  // Switch 5 on N5 Starter Kit Battery Board
    #define SWITCH_PULL  NRF_GPIO_PIN_PULLUP
    
    #define SWITCHES_NUMBER 5
    
    #define BSP_SWITCH_0 SWITCH_1
    #define BSP_SWITCH_1 SWITCH_2
    #define BSP_SWITCH_2 SWITCH_3
    #define BSP_SWITCH_3 SWITCH_4
    #define BSP_SWITCH_4 SWITCH_5
    
    #define SWITCHES_MASK 0x01000261
    
    #endif

    Want to use one button from it,how can I use it at hardware as well as in software?

  • Thank you for response.I want only one button in use #define BUTTON_A     23    for reset #define APP_ADV_TIMEOUT_IN_SECONDS      180,    this time.Then what exact changes are require to do that?

  • The easiest may just be to have a global variable that you set on button press, and when advertisement time-out (BLE_ADV_EVT_IDLE event), then check if the global variable is set, and if set then clear global variable and start advertisement again.

Related