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

[nRF51-ble-app-uart-static-passkey] Calling app_timer_start at BLE_GAP_EVT_CONNECTED

Using,

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

Hi, I modified some codes of main.c. main_edited.c

This file can be compiled after adding ble_dis.c.

The main changes are

Change1

Change1-1

  1. Changing device name, added DIS (Device Info Service) and infinite advertising.

This timer starts after connection / disconnection. The call of the timeout handler can be observed from the LEDs.

Change2

  1. Added a timer. This timer just makes the LED 0, LED 1 to blink

Change3

  1. Edited passkey properly for SDK7.2.

Change4

  1. Enabled whitelist advertising

  2. If a NUS packet was sent from the central, it echoes back the same packet.

This is for checking the connection.

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

One surprising this is that

the test_timer_timeout is not called after the BLE_GAP_EVT_CONNECTED.

I made the timer to start after connection, but I observed that RTC1_IRQHandler wasn't called.

However, the disconnection event called test_timer_timeout.

Why RTC1_IRQHandler isn't called after connection event happened?

Although I changed the timeout_ticks for app_timer_start and enabled the scheduler, the result was same.

Is there a change to be done in order to trigger RTC1_IRQHandler after connection?

-Regards, Mango

Parents
  • FormerMember
    0 FormerMember

    For development, I would recommend you to use the latest version of the SDK, v10.0.0, and implement static passkey, and the timer. Adding static passkey should be fairly straight forward, and should be very similar to the github example.

    With SDK 10.0.0, the timer should be implemented the following way:

    1) Define the timer as a static variable: APP_TIMER_DEF(m_connected_timer_test_id);

    2) Initialize and create the timer in main():

    int main(void)
    {
       ...
        
        // Initialize.
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
        ...
    	err_code = app_timer_create(&m_connected_timer_test_id, APP_TIMER_MODE_SINGLE_SHOT, connected_timer_test_timeout_handler);
    	APP_ERROR_CHECK(err_code);
    	
        ...
        
        // Enter main loop.
        for (;;)
        {
            power_manage();
        }
    }
    

    3) Create timeout handler

    static void connected_timer_test_timeout_handler(void * p_context)
    {
        uint32_t err_code;
    		err_code = bsp_indication_set(BSP_INDICATE_ALERT_3);
        APP_ERROR_CHECK(err_code);
    }
    

    4) Start the timer where you need it, for example in BLE_GAP_EVT_CONNECTED:

    err_code = app_timer_start(m_connected_timer_test_id, timeout_ticks, NULL);  
    APP_ERROR_CHECK(err_code);
    
  • @Mango: I suggest you to test first with just the timer, you can try to comment out start advertising part, and simply start the app_timer. Note that APP_TIMER_MAX_TIMERS is set to three in your application, I'm not sure if in your application you create other timers (for example in device manager) that exceed 3.

    There should not be a problem starting timer within a connection event.

Reply
  • @Mango: I suggest you to test first with just the timer, you can try to comment out start advertising part, and simply start the app_timer. Note that APP_TIMER_MAX_TIMERS is set to three in your application, I'm not sure if in your application you create other timers (for example in device manager) that exceed 3.

    There should not be a problem starting timer within a connection event.

Children
No Data
Related