GPIOTE function disabled

In my project, button ,charge state check and ACC sensor Interrupt pin, use GPIOTE; when The device is charging, keep this state one night,not unplugging the charger.when i double click on the button,The motor will vibrate,that's ok. but when i double click again, sonmething wrong happend,my device can normal broadcast,but my button, and charge state check ... all functions related to GPIOTE are disabled;then unplugging the charger and plug in the charger, It's normal again. I would like to know what causes GPIOTE failure, but the device will broadcast normally 

Parents
  • Hi,

    The motor will vibrate,that's ok. but when i double click again, sonmething wrong happend,my device can normal broadcast,but my button, and charge state check ... all functions related to GPIOTE are disabled

    You need to share more detailed information regarding your application. I'm not totally sure what clicking the button does, can you elaborate? 

    My understanding is that you expect the motor to vibrate once click the button, and that it works once but on the second time the motor doesn't vibrate? Is my understanding correct?  Have you tried debugging your application and see if the program reacts when the button is pressed?

    regards

    Jared

  • thans for your help,

      in my application,  double click on the button can trigger the motor vibration.on the second time the motor doesn't vibrate means my button function disabled. I have verified  my button does't work. this only happens when I'm charging and not unplugging the charger. becaue in my application, charge also use GPIOTE to indicate charging,full charge state.in fact, these questions are all related to GPIOTE,and only GPIOTE had problems.I don't know why this happened.

    .

  • Hi,

    Can you show how you setup the GPIOTE for the charging and the vibration part? Preferably, can you share your code and elaborate a bit more on the charging and the vibration part?

    I can make this case private first if you prefer it. 

    thank you,

    regards

    Jared 

  • that is my charging  check code:

    if (!nrf_drv_gpiote_is_init()) {
            APP_ERROR_CHECK(nrf_drv_gpiote_init());
        }
    
        nrf_drv_gpiote_in_config_t charge_in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
        charge_in_config.pull                       = NRF_GPIO_PIN_PULLUP;
    
        APP_ERROR_CHECK(nrf_drv_gpiote_in_init(CHARGE_PIN, &charge_in_config, charge_evt_handler));
        APP_ERROR_CHECK(nrf_drv_gpiote_in_init(CHARGE_DONE_PIN, &charge_in_config, charge_evt_handler));
    
        nrf_drv_gpiote_in_event_enable(CHARGE_PIN, true);
        nrf_drv_gpiote_in_event_enable(CHARGE_DONE_PIN, true);
    
        APP_ERROR_CHECK(app_timer_create(&m_charge_timer,APP_TIMER_MODE_SINGLE_SHOT,charge_cb));
        
        
        
        ////////////////
        
        static charge_cb(void *pcontex){
    
        
            if(!nrf_gpio_pin_read(CHARGE_PIN)){
                if(nrf_gpio_pin_read(CHARGE_DONE_PIN)){
                    NRF_LOG_ERROR("charging \n\r");
                    app_led_handle(LED_CHARGEING,LED_PIN_NUMBER_2);
                }
            }
            else{
                if(!nrf_gpio_pin_read(CHARGE_DONE_PIN)){
                    NRF_LOG_ERROR("charge over\n\r");
                    app_led_handle(LED_CHARGE_OVER,LED_PIN_NUMBER_3);
                }
                else{
                    NRF_LOG_ERROR("charge stop\n\r");
                    app_led_handle(LED_CHARGE_IDEL,LED_PIN_NUMBER_2);
    
                }
            }
    
            nrf_drv_gpiote_in_event_enable(CHARGE_PIN, true);
            nrf_drv_gpiote_in_event_enable(CHARGE_DONE_PIN, true);
    
            NRF_LOG_ERROR("charge pin leval is %d\n\r",nrf_gpio_pin_read(CHARGE_PIN));
            NRF_LOG_ERROR("charge done pin leval is %d\n\r",nrf_gpio_pin_read(CHARGE_DONE_PIN));
    
    }
    
    
    static void charge_evt_handler(nrf_drv_gpiote_pin_t irqPin, nrf_gpiote_polarity_t irq_action){
        
        NRF_LOG_ERROR("trigger pin is %d, action is %d\n\r",irqPin,irq_action);
    
        nrf_drv_gpiote_in_event_disable(CHARGE_PIN);
        nrf_drv_gpiote_in_event_disable(CHARGE_DONE_PIN);
    
        APP_ERROR_CHECK(app_timer_start(m_charge_timer,APP_TIMER_TICKS(50),NULL));
    
    }

    that is my motor vibration code:

    static void motor_work_on(void)
    {
        switch (m_motor_drv) {
            case MOTOR_DRV_LEVEL:
                nrf_gpio_cfg_output(m_motor_msg.motor_pin);
                NRF_LOG_INFO("MOTOR WORK \n\r");
                MOTOR_ON(m_motor_msg.motor_pin);
                APP_ERROR_CHECK(app_timer_start(motor_level_timer,
                                                APP_TIMER_TICKS(m_motor_msg.motor_time),
                                                NULL));
                break;
    
            case MOTOR_DRV_PWM: {
                static nrf_pwm_values_wave_form_t pwm_values[] = {
                    { 625, 0, 0, 6250 },  
                    { 11, 0, 0, 11 }
                };
    
                if (m_motor_state == MOTOR_STATE_ADV_TRIGGER) {
                   
                    static nrf_pwm_sequence_t pwm_seq = {
                        .values.p_wave_form = pwm_values,
                        .length             = NRF_PWM_VALUES_LENGTH(pwm_values),
                        .repeats            = 5, 
                        .end_delay          = 0
                    };
    
                    APP_ERROR_CHECK(nrf_drv_pwm_simple_playback(&m_pwm_motor,
                                                                &pwm_seq, 1, NRF_DRV_PWM_FLAG_STOP));
                } else {
                    static nrf_pwm_sequence_t pwm_seq = {
                        .values.p_wave_form = pwm_values,
                        .length             = NRF_PWM_VALUES_LENGTH(pwm_values),
                        .repeats            = 9, 
                        .end_delay          = 0
                    };
    
                    APP_ERROR_CHECK(nrf_drv_pwm_simple_playback(&m_pwm_motor,
                                                                &pwm_seq, 1, NRF_DRV_PWM_FLAG_STOP));
                }
            }
            break;
    
            default:
                break;
        }
    }
    
    void mt_motor_drv_init(uint8_t pin, motor_drv_t motor_drv)
    {
        m_motor_msg.motor_pin = pin;
        m_motor_drv = motor_drv;
        nrf_gpio_cfg_output(m_motor_msg.motor_pin);
    
        switch (m_motor_drv) {
            case MOTOR_DRV_LEVEL:
                APP_ERROR_CHECK(app_timer_create(&motor_level_timer,
                                                APP_TIMER_MODE_SINGLE_SHOT,
                                                motor_level_timeout_handller));
                break;
    
            case MOTOR_DRV_PWM: {
                nrf_drv_pwm_config_t const pwm_config = {
                    .output_pins = {
                        m_motor_msg.motor_pin,
                        NRF_DRV_PWM_PIN_NOT_USED,
                        NRF_DRV_PWM_PIN_NOT_USED,
                        NRF_DRV_PWM_PIN_NOT_USED
                    },
                    .irq_priority = APP_IRQ_PRIORITY_LOW,
                    .base_clock   = NRF_PWM_CLK_125kHz,
                    .count_mode   = NRF_PWM_MODE_UP,
                    .load_mode    = NRF_PWM_LOAD_WAVE_FORM,
                    .step_mode    = NRF_PWM_STEP_AUTO
                };
    
                APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm_motor, &pwm_config, motor_pwm_cb_handler));
            }
            break;
    
            default:
                break;
        }
    
        m_motor_state = MOTOR_STATE_IDLE;
        NRF_LOG_INFO("[%04d] Motor init.\r\n", __LINE__);
        APP_ERROR_CHECK(app_timer_create(&motor_polling_timer,
                                        APP_TIMER_MODE_SINGLE_SHOT,
                                        motor_polling_timeout_cb));
    }

    thank you,

Reply
  • that is my charging  check code:

    if (!nrf_drv_gpiote_is_init()) {
            APP_ERROR_CHECK(nrf_drv_gpiote_init());
        }
    
        nrf_drv_gpiote_in_config_t charge_in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
        charge_in_config.pull                       = NRF_GPIO_PIN_PULLUP;
    
        APP_ERROR_CHECK(nrf_drv_gpiote_in_init(CHARGE_PIN, &charge_in_config, charge_evt_handler));
        APP_ERROR_CHECK(nrf_drv_gpiote_in_init(CHARGE_DONE_PIN, &charge_in_config, charge_evt_handler));
    
        nrf_drv_gpiote_in_event_enable(CHARGE_PIN, true);
        nrf_drv_gpiote_in_event_enable(CHARGE_DONE_PIN, true);
    
        APP_ERROR_CHECK(app_timer_create(&m_charge_timer,APP_TIMER_MODE_SINGLE_SHOT,charge_cb));
        
        
        
        ////////////////
        
        static charge_cb(void *pcontex){
    
        
            if(!nrf_gpio_pin_read(CHARGE_PIN)){
                if(nrf_gpio_pin_read(CHARGE_DONE_PIN)){
                    NRF_LOG_ERROR("charging \n\r");
                    app_led_handle(LED_CHARGEING,LED_PIN_NUMBER_2);
                }
            }
            else{
                if(!nrf_gpio_pin_read(CHARGE_DONE_PIN)){
                    NRF_LOG_ERROR("charge over\n\r");
                    app_led_handle(LED_CHARGE_OVER,LED_PIN_NUMBER_3);
                }
                else{
                    NRF_LOG_ERROR("charge stop\n\r");
                    app_led_handle(LED_CHARGE_IDEL,LED_PIN_NUMBER_2);
    
                }
            }
    
            nrf_drv_gpiote_in_event_enable(CHARGE_PIN, true);
            nrf_drv_gpiote_in_event_enable(CHARGE_DONE_PIN, true);
    
            NRF_LOG_ERROR("charge pin leval is %d\n\r",nrf_gpio_pin_read(CHARGE_PIN));
            NRF_LOG_ERROR("charge done pin leval is %d\n\r",nrf_gpio_pin_read(CHARGE_DONE_PIN));
    
    }
    
    
    static void charge_evt_handler(nrf_drv_gpiote_pin_t irqPin, nrf_gpiote_polarity_t irq_action){
        
        NRF_LOG_ERROR("trigger pin is %d, action is %d\n\r",irqPin,irq_action);
    
        nrf_drv_gpiote_in_event_disable(CHARGE_PIN);
        nrf_drv_gpiote_in_event_disable(CHARGE_DONE_PIN);
    
        APP_ERROR_CHECK(app_timer_start(m_charge_timer,APP_TIMER_TICKS(50),NULL));
    
    }

    that is my motor vibration code:

    static void motor_work_on(void)
    {
        switch (m_motor_drv) {
            case MOTOR_DRV_LEVEL:
                nrf_gpio_cfg_output(m_motor_msg.motor_pin);
                NRF_LOG_INFO("MOTOR WORK \n\r");
                MOTOR_ON(m_motor_msg.motor_pin);
                APP_ERROR_CHECK(app_timer_start(motor_level_timer,
                                                APP_TIMER_TICKS(m_motor_msg.motor_time),
                                                NULL));
                break;
    
            case MOTOR_DRV_PWM: {
                static nrf_pwm_values_wave_form_t pwm_values[] = {
                    { 625, 0, 0, 6250 },  
                    { 11, 0, 0, 11 }
                };
    
                if (m_motor_state == MOTOR_STATE_ADV_TRIGGER) {
                   
                    static nrf_pwm_sequence_t pwm_seq = {
                        .values.p_wave_form = pwm_values,
                        .length             = NRF_PWM_VALUES_LENGTH(pwm_values),
                        .repeats            = 5, 
                        .end_delay          = 0
                    };
    
                    APP_ERROR_CHECK(nrf_drv_pwm_simple_playback(&m_pwm_motor,
                                                                &pwm_seq, 1, NRF_DRV_PWM_FLAG_STOP));
                } else {
                    static nrf_pwm_sequence_t pwm_seq = {
                        .values.p_wave_form = pwm_values,
                        .length             = NRF_PWM_VALUES_LENGTH(pwm_values),
                        .repeats            = 9, 
                        .end_delay          = 0
                    };
    
                    APP_ERROR_CHECK(nrf_drv_pwm_simple_playback(&m_pwm_motor,
                                                                &pwm_seq, 1, NRF_DRV_PWM_FLAG_STOP));
                }
            }
            break;
    
            default:
                break;
        }
    }
    
    void mt_motor_drv_init(uint8_t pin, motor_drv_t motor_drv)
    {
        m_motor_msg.motor_pin = pin;
        m_motor_drv = motor_drv;
        nrf_gpio_cfg_output(m_motor_msg.motor_pin);
    
        switch (m_motor_drv) {
            case MOTOR_DRV_LEVEL:
                APP_ERROR_CHECK(app_timer_create(&motor_level_timer,
                                                APP_TIMER_MODE_SINGLE_SHOT,
                                                motor_level_timeout_handller));
                break;
    
            case MOTOR_DRV_PWM: {
                nrf_drv_pwm_config_t const pwm_config = {
                    .output_pins = {
                        m_motor_msg.motor_pin,
                        NRF_DRV_PWM_PIN_NOT_USED,
                        NRF_DRV_PWM_PIN_NOT_USED,
                        NRF_DRV_PWM_PIN_NOT_USED
                    },
                    .irq_priority = APP_IRQ_PRIORITY_LOW,
                    .base_clock   = NRF_PWM_CLK_125kHz,
                    .count_mode   = NRF_PWM_MODE_UP,
                    .load_mode    = NRF_PWM_LOAD_WAVE_FORM,
                    .step_mode    = NRF_PWM_STEP_AUTO
                };
    
                APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm_motor, &pwm_config, motor_pwm_cb_handler));
            }
            break;
    
            default:
                break;
        }
    
        m_motor_state = MOTOR_STATE_IDLE;
        NRF_LOG_INFO("[%04d] Motor init.\r\n", __LINE__);
        APP_ERROR_CHECK(app_timer_create(&motor_polling_timer,
                                        APP_TIMER_MODE_SINGLE_SHOT,
                                        motor_polling_timeout_cb));
    }

    thank you,

Children
  • Hi,

    I have some additional questions:

    1. My understanding is that motor_work_on() will be called when you double click the button? Where is it called from?
    2. Can you use a debugger and see where you program is stuck when you try to double click again and nothing works? Does the program go into motor_work_on() when you double click and "nothing works"?
    3. Have you checked if there is any information from the logger module? What is the last printed log before it stops?

    regards

    Jared

Related