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

Which GPIO on nRf52382 can be configured as timer?

I'm using nRF 52383 and need one of the GPIO pins to clock an external device with 4MHz clock. Can any GPIO be configured as clock output or is there a specific group of GPIO's that should be used for this purpose? Looking forward to your reply.

Thank you Brane

Parents
  • Hi,

    The following code using GPIOTE with PPI gives a 4MHz output on pin 18.

    int main(void)
    {
        nrf_gpio_range_cfg_output(18); //Configure pin 18 as output
    
        NRF_CLOCK->TASKS_HFCLKSTART = 1; //Start high frequency clock
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
        {
             //Wait for HFCLK to start
        }
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; //Clear event
        
        
        //Configure GPIOTE to toggle pin 18 
        NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos |
                                GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos |
                                18 << GPIOTE_CONFIG_PSEL_Pos | 
                                GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos;
        
        //Configure timer
        NRF_TIMER1->PRESCALER = 0;
        NRF_TIMER1->CC[0] = 2;  // Adjust the output frequency by adjusting the CC.
        NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
        NRF_TIMER1->TASKS_START = 1;
        
        //Configure PPI
        NRF_PPI->CH[0].EEP = (uint32_t) &NRF_TIMER1->EVENTS_COMPARE[0];
        NRF_PPI->CH[0].TEP = (uint32_t) &NRF_GPIOTE->TASKS_OUT[0];
        
        NRF_PPI->CHENSET = PPI_CHENSET_CH0_Enabled << PPI_CHENSET_CH0_Pos;
        
        while (true)
        {
            // do nothing
        }
    }
    

    Because of pin crossbar almost any pin can be used, pin crossbar is essentially a mux that lets you chose any GPIO for any functionality. Please see the pin assignments for which pins are available for GPIO.

    Best regards,

    Øyvind

Reply
  • Hi,

    The following code using GPIOTE with PPI gives a 4MHz output on pin 18.

    int main(void)
    {
        nrf_gpio_range_cfg_output(18); //Configure pin 18 as output
    
        NRF_CLOCK->TASKS_HFCLKSTART = 1; //Start high frequency clock
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
        {
             //Wait for HFCLK to start
        }
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; //Clear event
        
        
        //Configure GPIOTE to toggle pin 18 
        NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos |
                                GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos |
                                18 << GPIOTE_CONFIG_PSEL_Pos | 
                                GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos;
        
        //Configure timer
        NRF_TIMER1->PRESCALER = 0;
        NRF_TIMER1->CC[0] = 2;  // Adjust the output frequency by adjusting the CC.
        NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
        NRF_TIMER1->TASKS_START = 1;
        
        //Configure PPI
        NRF_PPI->CH[0].EEP = (uint32_t) &NRF_TIMER1->EVENTS_COMPARE[0];
        NRF_PPI->CH[0].TEP = (uint32_t) &NRF_GPIOTE->TASKS_OUT[0];
        
        NRF_PPI->CHENSET = PPI_CHENSET_CH0_Enabled << PPI_CHENSET_CH0_Pos;
        
        while (true)
        {
            // do nothing
        }
    }
    

    Because of pin crossbar almost any pin can be used, pin crossbar is essentially a mux that lets you chose any GPIO for any functionality. Please see the pin assignments for which pins are available for GPIO.

    Best regards,

    Øyvind

Children
No Data
Related