ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
connections. First, let’s bring up one of the 20 user-defined
TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&timer, &timer_
PPI channels available to us:
cfg, timer_dummy_handler);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_alloc(&ppi_
channel);
initLED();
APP_ERROR_CHECK(err_code);
nrf_drv_timer_enable(&timer);
The next step of building the PPI/GPIOTE infrastructure
requires us to retrieve the event and task addresses:
As you can see, we initialize the major players
at the beginning of the main function. Recall that we
timer_compare_evt_addr = nrf_drv_timer_event_
preconfigured Timer0 with the Configuration Wizard. The
address_get(&timer, NRF_TIMER_EVENT_COMPARE0);
NRF_DRV_TIMER_DEFAULT_CONFIG macro pulls from
gpiote_led_task_addr = nrf_drv_gpiote_out_task_
the Timer0 entries we made in the Configuration Wizard,
addr_get(blueLED9);
which were deposited in sdk_config.h.
Note that we have been populating structures
Now that we have allocated an unused PPI channel
(sometimes using macros) and passing the contents of the
and retrieved the event and task addresses, we can put the
structures to functions. The beauty to this is that all you
PPI channel and task/event addresses together logically:
have to do is right-click on a structure you want to study
more closely within the Keil text editor and walk through
err_code = nrf_drv_ppi_channel_assign(ppi_
the structure contents from the initial structure declaration.
channel, timer_compare_evt_addr, gpiote_led_task_
Here’s the remainder of the main function code:
addr);
APP_ERROR_CHECK(err_code);
while (true)
{
The APP_ERROR_CHECK function verifies that our
// Do nothing.
function request was valid and processed without error. It
}
is good programming practice to include this check when
coding nRF52832 applications.
I loaded the compiled code and the blue LED is
Everything is in place. All that’s left to do is flip the
blinking.
switch and turn it all on:
More to Come
err_code = nrf_drv_ppi_channel_enable(ppi_
channel);
In the next installment of Design Cycle, we will
APP_ERROR_CHECK(err_code);
continue our exploration of the nRF52832. NV
nrf_drv_gpiote_out_task_enable(blueLED9);
} //end of initLED function
Keil Cortex-M MDK
The initLED function will be called from the main
Keil
function. For the lights to come on, we will need to throw
www.keil.com
some additional switches in the main function before we
call the initLED function:
Raytac MDBT42Q
ret_code_t err_code;
nRF52832 Module
Raytac
err_code = nrf_drv_ppi_init();
www.raytac.com
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_gpiote_init();
J-Link PRO
APP_ERROR_CHECK(err_code);
Segger
nrf_drv_timer_config_t timer_cfg = NRF_DRV_
www.segger.com
December 2016 57