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

current time gets 0 after connectiong with bluetooth

hi, i am using ble_uart example to take time when data arrives and time when data being sent over bluetooth. when i prints the time without connecting to bluetooth. then the time gives a value. but after connecting with bluetooth it gives 0. i dont know what makes it 0.

below is my code:

/**@snippet [Handling the data received over UART] */
void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
		uint8_t data[5];
    static uint8_t index,push = 0;
    uint32_t       err_code;
		static uint32_t previous_time,current_time,duration_time,waiting_time;
		waiting_time=450;
		

    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&data_array[index]));
            index++;
						push++;
						if(index%3 == 0)
						{
							count++;
							err_code = app_timer_cnt_get(&current_time);
							APP_ERROR_CHECK(err_code);
							
							err_code = app_timer_cnt_diff_compute(current_time,previous_time,&duration_time);
							APP_ERROR_CHECK(err_code);
							current_time = app_timer_ms(current_time);
							previous_time = app_timer_ms(previous_time);
							duration_time = app_timer_ms(duration_time);
							SEGGER_RTT_printf(0, "current:%d\tprevious:%d\tduration:%d\n",current_time,previous_time,duration_time);
							
							SEGGER_RTT_printf(0, "%x\t%x\t%x\n",data_array[0],data_array[1],data_array[2]);
									sendData(data_array,index);
									previous_time = current_time;
							index = 0;
							preCount=count;
						}						
							
            break;
}

what i am doing wrong here.

thanks!!

Parents
  • Hi, I have the same problem using sdk 9.0 and an application based on ble_app_uart. Timer init is identical as ble_app_uart (APP_TIMER_INIT called with same APP_TIMER_.. values)

    Call to app_timer_cnt_get() returns a correct value (around 33k tics/per sec) when the softdevice is not connected and returns 0 when softdevice is connected. If I disconect the app_timer_cnt_get() works again

    How did you fix this problem ? Thanks

    Edit: does app_timer_cnt_get requires to start a timer with timer_start to work ?

  • FormerMember
    0 FormerMember in reply to energy

    The app_timer module uses RTC1 and the softdevice uses RTC0, the softdevice should therefore not have any effect of the RTC1 value.

    When you are using app_timer with the softdevice, could you try to explicitly start app_timer using app_timer_start(..), and see if that changes anything?

  • How can you do that if your not using a self-made timer? I have the same issue but I don't understand why you would have to start a new timer just to read out the RTC1->Counter register?

  • FormerMember
    0 FormerMember in reply to Mathias

    As stated in the "Hardware peripheral" chapter in the Sotfdevice Specification, RTC0 is "blocked" when using the softdevice:

    Blocked: 

    The hardware peripheral is used by the SoftDevice and is outside the application sandbox.

    The application has no access. Interrupts from blocked peripherals are forwarded to the SoftDevice by the MBR and are not available to the application, even inside a Radio Timeslot API timeslot.

  • I'm not using RTC0, I'm using RTC1. I don't understand why I need to run a timer, just to ensure the RTC1 is run as well so that I can read the Counter register when needed. I solved it like that now, just by using a repeatable timer that I don't do anything else with. But I still don't understand why I would need that.

  • FormerMember
    0 FormerMember in reply to Mathias

    I don't understand what you mean, could you elaborate a little?

  • Well, I have the same problem as the two people above. If use the SoftDevice but don't connect (so just stay advertising), app_timer_cnt_get gives me the current value of the RTC1 Counter register, as expected. But when the advertiser connects with a central and thus becomes a peripheral, app_timer_cnt_get gives 0 constantly.

    The app_timer module is used in my application and initializes RTC1 with a prescaler of 0. Above you stated "When you are using app_timer with the softdevice, could you try to explicitly start app_timer using app_timer_start(..), and see if that changes anything?". How can you start the app_timer in general with that method (app_timer_start(..) ) ? From what I see in the infocenter, I can only use this method to start self defined timers that use RTC1 underneath. When I start such a timer (with an empty handler and repeated (not single mode) )  using app_timer_start, after a connection is established, app_timer_cnt_get doesn't give me 0 anymore but gives me seemingly correct counter values. But I don't understand why I need to start an unused timer to get this effect?

Reply
  • Well, I have the same problem as the two people above. If use the SoftDevice but don't connect (so just stay advertising), app_timer_cnt_get gives me the current value of the RTC1 Counter register, as expected. But when the advertiser connects with a central and thus becomes a peripheral, app_timer_cnt_get gives 0 constantly.

    The app_timer module is used in my application and initializes RTC1 with a prescaler of 0. Above you stated "When you are using app_timer with the softdevice, could you try to explicitly start app_timer using app_timer_start(..), and see if that changes anything?". How can you start the app_timer in general with that method (app_timer_start(..) ) ? From what I see in the infocenter, I can only use this method to start self defined timers that use RTC1 underneath. When I start such a timer (with an empty handler and repeated (not single mode) )  using app_timer_start, after a connection is established, app_timer_cnt_get doesn't give me 0 anymore but gives me seemingly correct counter values. But I don't understand why I need to start an unused timer to get this effect?

Children
  • FormerMember
    0 FormerMember in reply to Mathias

    I see. I had forgotten what this thread was about.

    It should not be necessary to to use the app_timer module, what is necessary is to explicitly start RTC1. You should get the same result if you do the following:

    NRF_RTC1->TASKS_START = 1;

  • Unfortunately, that doesn't seem to be working. If I explicitly start RTC1 using NRF_RTC1->TASKS_START = 1, and don't run the empty, self defined timer anymore, I again get 0 on every request for the RTC1 Counter register's value.

  • FormerMember
    0 FormerMember in reply to Mathias

    Is app_timer used somewhere in your application? I so, your timer and app_timer will share RTC1. In that case, could you try to use RTC2 instead for your timer?

     

     

  • App_timer is used in my application. And I'm using nRF51 so unfortunately, I can only use RTC1. But I don't need the timer I defined, I just need to get the value of the Counter register of RTC1 at any moment I want. And I don't understand why that gives me 0 when the SoftDevice and thus my application, is in a BLE connection, which is the same issue as the people above I believe. 

    I "fixed" the register giving 0 by starting a self defined timer when in a connection, but I don't understand why I would need to do that? If app_timer is used, I presume that RTC1 is thus active and used and thus the Counter register should be giving me correct values without needing me to start a self defined timer, no?

  • FormerMember
    0 FormerMember in reply to Mathias

    I just tested again reading the counter value, and it works fine to read NRF_RTC1-COUNTER, both when the device is advertising, and when in connected state (nRF51-DK, SDK 12.3.0, S132 v.2.0.1, ble_app_hrs)

    	case BSP_EVENT_KEY_0:
    						rtc_value = NRF_RTC1->COUNTER; //NRF_RTC1->CC[0];
    						NRF_LOG_INFO("RTC value: %d \n\r", rtc_value);
    

    Another option is to do the following:

    NRF_RTC1->CC[0] = NRF_RTC1->COUNTER;
    rtc_value = NRF_RTC1->CC[0];

Related