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

facing issues in timer

hi..... i am using nrf52832 , merged the uart and  timer example program . while i am debugging , debugged successfully , but timer is not working

actually i set the timer for one minute after completing the one minute it should send the data .  i am getting the data very quickly in this case i couldn't  found any timer 

Parents
  • is it possible you can post your code / setup or pieces of your code?

  • static void create_timers()
    {  
       uint32_t err_code;
    
        // Create timers
    
        err_code = app_timer_create(&m_led_a_timer_id,
                                    APP_TIMER_MODE_REPEATED,
                                   timer_sensor_event_handler);
      APP_ERROR_CHECK(err_code);
    }
    
    static timer_start(void)
    {
       uint32_t err_code;
        //uint32_t APP_TIMER_TICKS(50000);
       
           
        // Start application timers
        err_code = app_timer_start(m_led_a_timer_id, APP_TIMER_TICKS(50000), NULL);
        APP_ERROR_CHECK(err_code);
         NRF_LOG_INFO("SUCCESS1");          
    
    }
    
    
    
    /**@brief Application main function.
     */
    int main(void)
      {
        bool erase_bonds;
    
        // Initialize.
       
      
       
       
        uart_init();
        log_init();
       // timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
    app_timer_init();
         create_timers();
        
        // Start execution.
        printf("\r\nUART started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        advertising_start();
       timer_start();
       
         twi_init();
         MAX30_set_mode();
         
    
        
       while (true)
        {
            nrf_delay_ms(6000);
      uint32_t err_code;
           while (m_xfer_done == false);
    
             m_xfer_done = false;
                    
    		uint8_t reg[2] = {0x00U};
            err_code = nrf_drv_twi_tx(&m_twi,LM75B_ADDR, reg, sizeof(reg), true);
    		APP_ERROR_CHECK(err_code);
    		while (m_xfer_done == false);
    		nrf_delay_ms(5);
    		
    	        m_xfer_done = false;
    		ret_code_t err_code1 = nrf_drv_twi_rx(&m_twi,LM75B_ADDR, &m_sample, sizeof(m_sample));
    		APP_ERROR_CHECK(err_code1);
                    NRF_LOG_INFO("%d", m_sample);
                     
     
    }
                  for (;;)
        {
            idle_state_handle();
        }
    
          
          }
             
       

  • ok, but to implement  this . i am not that much good at program, is there any sample program like this so that i can get some idea 

  • I dont believe there is sample exactly but the above code you provide is very close to the functionality described. 

    You already have the 50s timer. instead of toggling an led you toggle a variable. I believe you mentioned 60s on while sending data and then 60s off. 120s period between on times. 

    bool yourflag = false;

    to toggle => yourflag = !yourflag. This would be the logic inside the timer handler.

    static void timer_sensor_event_handler(nrf_timer_event_t event_type, void* p_context)
    {
    yourflag = !yourflag;
    }

    Then in your main you would only advertise when your flag is true and when your flag is false stop and sleep.

    Note "sleep" still will not be deep power off sleep because you still need your timer to run so the RTC clock will still be ticking away. Power will be much less than advertising the entire time.

    When flag is set you call start advertising making sure that it is only called once.

    then once timer toggles flag you disconnect gatt and then idle.

    If you need more assistance or some rough pseudo code please let me know.

  • yeah sure i will look into and get back to you 

  • how to set the flag ,if  i want to check the some data if it reaches certain limit , and then  it should start advertise and  send the data ,and enter into the sleep ,  only when it reaches the certain level it should advertise and connect

  • i have tried but i can't able control the ble advertising , i have written the code when it reaches the threshold (beyond the limit value) then it should start advertise and send the data over ble ,how to connect automatically 

Reply Children
No Data
Related