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

Before enter system on idle mode call sd_ble_gap_adv_stop(m_adv_handle) then can not wake up use gpiote

Hi all:

I am using sdk 16.0.When put system on idle mode call two times sd_app_evt_wait it works well.But I want to save power,so before enter idle mode,but when I call the sd_ble_gap_adv_stop(m_adv_handle) api,after I can not wake up from idle mode,if I don not call sd_ble_gap_adv_stop api I can wake up from idle mode using keybutton.

Any one can tell me what 's the problem?Thanks.

Parents
  • void prepareSleep()
    {
           nrf_gpio_cfg_output(SENSOR_VCC_CE_PIN);
           nrf_gpio_pin_write(SENSOR_VCC_CE_PIN,0);
           
           //sensor
           nrf_gpio_cfg_output(SENSOR_1_PIN);
           nrf_gpio_cfg_output(SENSOR_2_PIN);
           nrf_gpio_cfg_output(SENSOR_3_PIN);
           nrf_gpio_pin_write(SENSOR_1_PIN,0);
           nrf_gpio_pin_write(SENSOR_2_PIN,0);
           nrf_gpio_pin_write(SENSOR_3_PIN,0);
        
           
           nrf_drv_twi_disable(&m_twi);
           nrf_drv_twi_uninit(&m_twi);
           
           
           nrf_gpio_cfg_output(TM1650_ENABLE_PIN);
           nrf_gpio_pin_write(TM1650_ENABLE_PIN,0);
           
           nrf_gpio_cfg_output(TM1650_SCL_PIN);
           nrf_gpio_cfg_output(TM1650_SDA_PIN);
           nrf_gpio_pin_write(TM1650_SCL_PIN,0);
           nrf_gpio_pin_write(TM1650_SDA_PIN,0);
           
           //EEPROM
           nrf_gpio_cfg_output(IIC_CLK_PIN);
           nrf_gpio_cfg_output(IIC_SDA_PIN);
           nrf_gpio_pin_write(IIC_CLK_PIN,1);
           nrf_gpio_pin_write(IIC_SDA_PIN,1);
            
            //LED
            nrf_gpio_cfg_output(BLE_BLINK_LED);
            nrf_gpio_cfg_output(CHARGE_LED);
            nrf_gpio_pin_write(BLE_BLINK_LED,1);
            nrf_gpio_pin_write(CHARGE_LED,1);
            
            nrf_gpio_cfg_input(CHRG_PIN,NRF_GPIO_PIN_PULLUP);
            nrf_gpio_cfg_input(STDBY_PIN,NRF_GPIO_PIN_PULLUP);
            
            nrf_gpio_cfg_output(MOTOR_PIN);
            nrf_gpio_pin_write(MOTOR_PIN,0);   
    }
    void enterSystemIdle()
    {
        uint8_t cmd=0x10;
        if(systemOnIdle==0)
        {
            NRF_LOG_INFO("enterSystemIdle");
            bsp_board_leds_off();
            nrf_drv_twi_tx(&m_twi, TM1650_REGISTER, (uint8_t *)&cmd, 1, false);
            disableTM1650();
            systemOnIdle=1;
            prepareSleep();
    //        stopAdv();//if comment this line after in idle mode,can not wake up use keybutton
            sd_app_evt_wait();
            sd_app_evt_wait();
            nrf_gpio_pin_write(BLE_BLINK_LED,0);//indicate whether in system on idle mode
        }
    }
    
    void enterSystemOn()
    {
        if(systemOnIdle==0)
        {
            return;
        }
        NRF_LOG_INFO("enterSystemOn");
        bsp_board_init(BSP_INIT_LEDS);
        sensorEnable();
        twi_init();
        enableTM1650();
        motorInit();
    //    startAdv();
        TM1650_power_on();
        blinkLEDBaseTime=(NRF_RTC0->COUNTER)>>15;
        powerOffBaseTime=(NRF_RTC0->COUNTER)>>15;
        systemOnIdle=0;
        showType=0;
        initTM1650Show();
        startCommonTimer();
    }
    
    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        nrf_drv_gpiote_out_toggle(CHARGE_LED);
        enterSystemOn();
    }
    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        nrf_drv_gpiote_out_toggle(CHARGE_LED);
        enterSystemOn();
    }
    
    //Key button init
    void keyInit()
    {
        ret_code_t err_code;
        nrf_drv_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
        in_config.pull = NRF_GPIO_PIN_PULLUP;
    
        err_code = nrf_drv_gpiote_in_init(POWERKEY_BUTTON_PIN, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_event_enable(POWERKEY_BUTTON_PIN, true);
    }
    
    
    //In a peroid timer check RTC count then call the enterSystemIdle()
    static void common_timeout_handler(void * p_context)
    {
        if((NRF_RTC0->COUNTER)>>15>=(powerOffBaseTime+SYSTEM_IDLE_DELAY)&&SportModeStatus==0)//120
        {
            enterSystemIdle();
        }
    }

  • after I can not wake up from idle mode

     How do you know that you've not woken up?



    why do you call sd_app_evt_wait twice?

Reply Children
Related