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

how to enable gpio pin after button events

Hello

I wrote the program by referring the some examples after compiling the program GPIO pin becomes high immediately (3.3V ) bu my aim is to make the GPIO pin as output only after the button press so anyone suggest me how to make the function like that please refer my example and help me if possible because am a new learner so all ideas and helps will eb greatly appreciated

thank you

  • Hi.

    Since you did not write which pins you are talking about, i assume (from reading the code) that you mean pin 6 and 7.

    Inside init_gpio(); you do the following:

        nrf_gpio_range_cfg_input(BUTTON_1, BUTTON_2, NRF_GPIO_PIN_PULLUP);//
        nrf_gpio_range_cfg_output(0, 7); 
    	nrf_gpio_pin_set(6); //clear the LED                              
        nrf_gpio_pin_set(7);//clear the LED
    

    The last two lines will set pin 6 and 7 high. If you comment out these two lines, and put them inside your button handler instead, they will stay low until the button is pressed.

    case BUTTON_1:		 
         app_timer_start(m_timer_id, MS_TO_TICKS(BUTTON_PRESS_TIME_MS), NULL); 
         nrf_gpio_pin_set(6); //clear the LED                              
         nrf_gpio_pin_set(7);//clear the LED
         break;
    
  • thanks for your reply i managed to do can you tell me i want to set the pin 6 and pin 7 in high drive mode i am using this function based on some other post

    NRF_GPIO->PIN_CNF[6] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos);

    does this will make the pin 6 drive in 5mA current mode ? how can i check this pin 6 is providing 5mA? can you give me some information about his HOH1and HOD1 because it is not clear for me

  • See the Reference Manual page 68.

    S0S1 0 Standard '0', standard '1'
    H0S1 1 High drive '0', standard '1'
    S0H1 2 Standard '0', high drive '1'
    H0H1 3 High drive '0', high 'drive '1''
    D0S1 4 Disconnect '0' standard '1'
    D0H1 5 Disconnect '0', high drive '1'
    S0D1 6 Standard '0'. disconnect '1'
    H0D1 7 High drive '0', disconnect '1'
    

    H0H1 means that the pin is in high drive both when it is low (0), and when it is high (1). H0D1 Means that it is in high drive when it is low (0), and disconnected when it is high (1).

    If you want to measure current, use an ampere meter.

  • In my project i prefere to use HODI because intially i configure the pin 6 as output so set to high(nrf_gpio_pin_set) so that it can produce 5mA at the output and make the buzzer beep little more louder after that i will clear that pin 6 to low (nrf_gpio_pin_clear)so for this function HOD1 is better or HOH1? can you suggest me whicch is more preferable and overall less power consumption?

Related