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!!

  • Thanks for taking the effort to test it. I really appreciate your help so far.

    I also tried it on the ble_app_hrs (I use nRF51-DK, SDK 11, S130 v2.0) with the push of button 2 printing the COUNTER register. I also get non-zero and seemingly correct values both in advertising and connected state.

    But when I try the same on my peripheral example (so also with a push on button 2 printing the COUNTER register) I still get strange results in connected state. In advertising state it prints fine, but in connected state it starts printing the same values after each other:

    839
    167
    906
    167
    167
    167
    167
    167
    167
    167
    168
    167
     ...

    So a bit strange. I used to print the values in the radio off event of the radio notification handler and there the register values still give 0 in the connected state. I guess it will have something to do with my example specifically but I wouldn't know what I do wrong. It's just a application that reads out an accelerometer with I2C and sends the measured data over a BLE connection. Could it have something to do with the TWI operation?

  • FormerMember
    0 FormerMember in reply to Mathias

    In the button push event, could you do two read-outs of the  RTC1 value, to check if the RTC1 value changes. It should give an indication of whether RTC1 is running or not.

    	case BSP_EVENT_KEY_0:
    						rtc_value = NRF_RTC1->COUNTER; 
    						NRF_LOG_INFO("RTC value: %d \n\r", rtc_value);
    						nrf_ms_delay(5);
    						rtc_value = NRF_RTC1->COUNTER; 
    						NRF_LOG_INFO("RTC value 2: %d \n\r", rtc_value);
    

  • FormerMember
    0 FormerMember in reply to Mathias

    I cannot understand anything else other than the RTC1 is not running. Could you explicitly start the RTC and then immediately read its values:

    	case BSP_EVENT_KEY_0:
    	                    RTC1->TASKS_START = 1;
    	                    nrf_ms_delay(5);
    						rtc_value = NRF_RTC1->COUNTER; 
    						NRF_LOG_INFO("RTC value: %d \n\r", rtc_value);
    						nrf_ms_delay(5);
    						rtc_value = NRF_RTC1->COUNTER; 
    						NRF_LOG_INFO("RTC value 2: %d \n\r", rtc_value);
    

Related