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

Simple PPI GPIOTE

I am trying to use a remaining timer/counter in the nrf52832 as a divide by 64 counter to get rid of an off board MC74HC4060 counter chip we are using for I2S from an external 1.024 Mhz clock.   We are using an external clock because there is no way to get this exact frequency (1.024Mhz clock, divide by 64, and LR Clock for I2S) using the on board 32Mhz clock.

Here is a function I have that should take a high to low transition on pin 11, and toggle pin 12.  Pin 12 is not toggling, but is sitting high.  I should be able to use the PPI to go from GPIOTE to GPIOTE, right?  When I get this working, I will put a 32 bit counter on the 1.024Mhz line and count high to low transitions, then toggle pin 12 and clear the counter at each count to 32. 

 Am I missing some important step?

 

#define LR_CLOCK_PIN_IN 20 
#define M1024_CLOCK_PIN_IN 11  
#define LR_CLOCK_PIN_OUT 12


void toggle_init(void) {
uint32_t err_code;

if(!nrf_drv_gpiote_is_init() ) {
                 nrf_drv_gpiote_init() ;
                 nrf_drv_ppi_init();  
                  }

 nrf_ppi_channel_t ppi_channel;  


    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);    
    in_config.pull = NRF_GPIO_PIN_PULLDOWN;

  err_code =   nrf_drv_gpiote_in_init(M1024_CLOCK_PIN_IN, &in_config, empty_in_pin_handler);
  APP_ERROR_CHECK(err_code);

   nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(true); // true because it is initially high. 
    err_code = nrf_drv_gpiote_out_init(LR_CLOCK_PIN_OUT, &out_config);
    APP_ERROR_CHECK(err_code);



err_code =  nrf_drv_ppi_channel_alloc(&ppi_channel);
APP_ERROR_CHECK(err_code);


    uint32_t LRCLK_toggle_task_addr    = nrf_drv_gpiote_out_task_addr_get(LR_CLOCK_PIN_OUT); 
    uint32_t gpiote_evt_addr_2          = nrf_drv_gpiote_in_event_addr_get(M1024_CLOCK_PIN_IN);

  err_code = nrf_drv_ppi_channel_assign(ppi_channel , gpiote_evt_addr_2, LRCLK_toggle_task_addr); 
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_enable(ppi_channel);
   APP_ERROR_CHECK(err_code);
   nrf_drv_gpiote_in_event_enable(M1024_CLOCK_PIN_IN, false);  // no interupt enable so last arg is false
   nrf_drv_gpiote_out_task_enable(LR_CLOCK_PIN_OUT);

   

}

Parents Reply Children
No Data
Related