0

RTC stops after disconnet from Android

MnCi1990 gravatar image

asked 2017-03-09 10:24:27 +0200

amiguels gravatar image

updated 2017-03-21 13:22:58 +0200

Hi, I am using nrf51822 chip. I am using RTC to generate irq with CC. Everything works fine for IOS and old Android version. New android version makes 2 things when I disconnect:

1) change register of CC[0] value so I changed to generate IRQ from CC[1]:

void lfclk_config(void)
{
    ret_code_t err_code = nrf_drv_clock_init(NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request();
}

    uint32_t err_code;

    //Initialize RTC instance
    err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_handler);
    APP_ERROR_CHECK(err_code);

    //Enable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc,false);

    //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds

    err_code = nrf_drv_rtc_cc_set(&rtc,1,P*60*8,true);
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc);

2) stops RTC after disconnect.

I don't have any idea why on IOS works fine but on new Android it doesn't.

Thanks for help in advance.

edit retag flag offensive close delete report spam

Comments

Sorry but it doesn't make sense that any external BLE device by connecting influences state of nRF5x registers like this. It must be code running on nRF5x chip which causes it, e.g. Soft Device. What SD are you running? What RTC instance are you using, how you initialize it etc.?

endnode ( 2017-03-09 11:29:08 +0200 )editconvert to answer

Hi Marcin,

Could you make sure you don't have any other code or other module that may use the RTC ?

Which value the CC[0] changed to after you disconnect from the new Android phone ?

Which Android version was that and which phone did you use ?

Could you provide the nRF UART version with your modification that can reproduce the issue ?

Hung Bui ( 2017-03-09 16:05:23 +0200 )editconvert to answer

2 answers

Sort by » oldest newest most voted
0
hungbui gravatar image

answered 2017-03-20 15:39:40 +0200

Hi Marcin,

I made an example with RTC1 and SDK v10 S110v8.0 You can see RTC1 CC[0] is printed out continuously. Could you please check, you can use make to compile, but I attached also the .hex I compiled.

ble_app_uart-RTC.zip

edit flag offensive delete publish link more
0
MnCi1990 gravatar image

answered 2017-03-09 12:03:50 +0200

amiguels gravatar image

updated 2017-03-21 13:24:07 +0200

I know it doesn't have any sense. I use soft device 110, I use RTC 1 to get irq. This is my initialization code. It's weird that at IOS or Android with old version everything works fine, but when I getting disconnet with new Android the register is changing and RTC stops. Main loop and other tasks works fine. It`s happens even when I am using NRF uart application.

void lfclk_config(void)
{
    ret_code_t err_code = nrf_drv_clock_init(NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request();
}

const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(1);

void rtc_config(void)
{
    uint32_t err_code;

    //Initialize RTC instance
    err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_handler);
    APP_ERROR_CHECK(err_code);

    //Enable tick event & interrupt
    nrf_drv_rtc_tick_enable(&rtc,false);

    //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds

    err_code = nrf_drv_rtc_cc_set(&rtc,1,2*60*8,true);
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&rtc);


}

BLE config here:

uint32_t BLE_config(void)
{
    uint32_t err_code;

    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);


    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init(APP_ADV_START_TIMEOUT_IN_SECONDS);
    conn_params_init();

    //err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    //APP_ERROR_CHECK(err_code);

    return err_code;
}

static void ble_stack_init(void)
{
    uint32_t err_code;

    // Initialize SoftDevice.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

    // Enable BLE stack.
    ble_enable_params_t ble_enable_params;
    memset(&ble_enable_params, 0, sizeof(ble_enable_params));
#if (defined(S130) || defined(S132))
    ble_enable_params.gatts_enable_params.attr_tab_size   = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
#endif
    ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
    err_code = sd_ble_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);

    // Subscribe for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

static void gap_params_init(void)
{
    uint32_t                err_code;
    ble_gap_conn_params_t   gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

    err_code = sd_ble_gap_device_name_set(&sec_mode,
                                          (const uint8_t *) DEVICE_NAME,
                                          strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    memset(&gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency     = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);
}

static void services_init(void)
{
    uint32_t       err_code;
    ble_nus_init_t nus_init;

    memset(&nus_init, 0, sizeof(nus_init));

    nus_init.data_handler = nus_data_handler;

    err_code = ble_nus_init(&m_nus, &nus_init);
    APP_ERROR_CHECK(err_code);
}

void advertising_init(uint16_t timeout)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
    ble_advdata_t scanrsp;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));
    advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance = true;
    advdata.flags=BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;
    ble_adv_modes_config_t options = {0};
    options.ble_adv_fast_enabled  = BLE_ADV_FAST_ENABLED;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = timeout;
    options.ble_adv_slow_enabled = BLE_ADV_SLOW_ENABLED;
    options.ble_adv_slow_interval = 2056;
    options.ble_adv_slow_timeout = timeout;

    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
}

static void conn_params_init(void)
{
    uint32_t               err_code;
    ble_conn_params_init_t cp_init;

    memset(&cp_init, 0, sizeof(cp_init));

    cp_init.p_conn_params                  = NULL;
    cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
    cp_init.next_conn_params_update_delay  = NEXT_CONN_PARAMS_UPDATE_DELAY;
    cp_init.max_conn_params_update_count   = MAX_CONN_PARAMS_UPDATE_COUNT;
    cp_init.start_on_notify_cccd_handle    = BLE_GATT_HANDLE_INVALID;
    cp_init.disconnect_on_fail             = false;
    cp_init.evt_handler                    = on_conn_params_evt;
    cp_init.error_handler                  = conn_params_error_handler;

    err_code = ble_conn_params_init(&cp_init);
    APP_ERROR_CHECK(err_code);
}

I post the logs from terminal from 3 phones.

rtc counter CC

Android 4.3 Samsung gt-i9300 with CC[0]: image description

Iphone 6S with system 10.2.1 with CC[0]: image description

and now Android 7.0 Samsung s7 edge with CC[0]: image description

Android 7.0 Samsung s7 edge with CC[1]: image description

Here is my code, sorry for a mess but this is just a test code: BLE_NEW_mod.rar

Now it`s working. Here is log:

image description

The problem was in using app_timer library.

Thanks a lot for help!

edit flag offensive delete publish link more

Comments

@Marcin: Please provide code that reproduce the issue. From the log, doesn't seem the CC changed when it's disconnected but when in connection.

Hung Bui ( 2017-03-10 11:02:38 +0200 )editconvert to answer

@Marcin: It would be easier if you have a Keil project so I can test here.

Are you sure there is nothing else in the application that can affect RTC? Could you try to modify the ble_app_uart to show the issue ?

You can also try to sniff a sniffer trace and compare between Android 4.3 and Android 7.0 on what they do after connection and spot the different.

Which app did you use on the phone ?

I noticed that CC changed before disconnection.

Hung Bui ( 2017-03-13 16:59:33 +0200 )editconvert to answer

I put my code under the terminal logs if you can just check it, this is eclipse project. I`m sure that RTC 1 is used just for this one task. I used NRF uart on all phones but also the application wrote by myself in xamarin, I am getting the same result. This is not the application fault beacuse this is just the disconnect event. I know that you see that CC has changed at connect, but it is not true. This logs I send by uart and this is sending when event of disconnect is done. CC is changing when I click disconnect at application on my phone and then it takes time to send infromation about disconnect.

Marcin ( 2017-03-14 10:49:33 +0200 )editconvert to answer

Hi Marcin,

I couldn't build your project with gcc with the Makefile provided in the \Release folder. I tried to flash the BLE_NEW.hex and BLE_S110_TEST_MM.hex and S110v8.0 on our DK but it didn't seem to advertise.

I strongly suggest you to use any of our example in the SDK and add the RTC code to test. This way we can narrow down if the issue is related to your code or not.

Hung Bui ( 2017-03-14 16:40:45 +0200 )editconvert to answer

Please try to flash BLE_NEW_mod.hex from Release folder. Also I will try today to add rtc to your example. I am using sdk 10. Which example would be the best for that test in your opinion?

Marcin ( 2017-03-15 08:14:21 +0200 )editconvert to answer

Hi Marcin, Sorry I tried to compile your project and make.exe erased BLE_NEW_mod.hex file.

I tried again with the file from .zip you provided, and can see the log printing out on the screen. Unfortunately, I don't have an S7 edge for testing ( I was testing with S6) and couldn't reproduce the issue.

Please let me know your result when you test with the example we provided.

Looking at your code I noticed that you haven't initialize the CCCD value of the UART_TX characteristic. You should handle it in BLE_GATTS_EVT_SYS_ATTR_MISSING event. Here is what we do in the uart example:

case BLE_GATTS_EVT_SYS_ATTR_MISSING:
    // No system attributes have been stored.
    err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
    APP_ERROR_CHECK(err_code);
    break; // BLE_GATTS_EVT_SYS_ATTR_MISSING
Hung Bui ( 2017-03-15 14:10:18 +0200 )editconvert to answer

I added now this event above and it has same behaviour, but I am changing the ble_app_uart example now, so I should have soon the result. I try to modify the ble_app_uart example, but when I add #include nrf_drv_rtc.h I am getting error that multiple definition of RTC1_IRQHandler' also when I add the #include nrf_drv_clock.h I am getting that error: make[1]: *** Brak reguł do zrobienia obiektu_build/nrf_drv_clock.o', wymaganego przez `nrf51422_xxac_s110'. Stop.

Maybe you have an example when is used softdevice 110 where device getting IRQ by comparing CC and wake up from power_manage?

Marcin ( 2017-03-15 15:49:28 +0200 )editconvert to answer

Hi Marcin,

Sorry I forgot to point out. In most of our example we already use RTC1 in our app timer library. In ble_app_uart we used if for bsp to handle the button and LED and the connection parameter update.

If you print out RTC1->CC[0] in the main loop you may be able to check if the issue also happens on those example.

Hung Bui ( 2017-03-16 16:12:01 +0200 )editconvert to answer

It has all the time 0 value, tell me how can I wake up module from power manage every 1 min,2 min and so on? NRF_RTC1->COUNTER is also 0.

Marcin ( 2017-03-17 11:45:46 +0200 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools

2 followers

Stats

Asked: 2017-03-09 10:24:27 +0200

Seen: 100 times

Last updated: Mar 21