the blue LED (pin 9) will behave. On the occurrence
of an event, the blue LED will toggle. GPIOTE_
CONFIG_OUT_TASK_TOGGLE is actually a macro:
APP_ERROR_CHECK(err_code);
#define GPIOTE_CONFIG_OUT_TASK_TOGGLE(init_high \
{ \
.init_state = init_high NRF_GPIOTE_INITIAL_ \
VALUE_HIGH : NRF_GPIOTE_INITIAL_VALUE_LOW, \
.task_pin = true, \
The GPIOTE_CONFIG_OUT_TASK_TOGGLE macro
argument (init_high) determines the initial state of the
GPIO pin. A false argument sets the pin driving the blue
LED initially low, which extinguishes the LED. The macro
contents also identify the GPIO pin driving the blue LED as
a task-controlled GPIO pin that will toggle on the reception
of an event.
The contents of the GPIOTE_CONFIG_OUT_TASK_
TOGGLE macro are used to populate the nrf_drv_gpiote_
n SCREENSHOT 6. The Configuration Wizard allows
out_config_t structure:
us to select the drivers and libraries we wish to include
in our application. Here, we’ve turned on the PPI and
typedef struct
Timer drivers.
{
nrf_gpiote_polarity_t action;
nrf_ppi_channel_t ppi_channel;
/**< Configuration of the pin task. */
//PPI channel type
nrf_gpiote_outinit_t init_state;
ret_code_t err_code;
/**< Initial state of the output pin. */
nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_
bool task_pin;
OUT_TASK_TOGGLE(false);
/**< True if the pin is controlled by */
/**< a GPIOTE task. */
err_code = nrf_drv_gpiote_out_init(blueLED9,
} nrf_drv_gpiote_out_config_t;
&config);
Let’s turn our attention back to Timer0. We want to
make sure we blink the blue LED slow enough for the
We have also specified how the GPIO pin driving
human eye to pick it up:
nrf_drv_timer_extended_compare(&timer, (nrf_
timer_cc_channel_t)0, 500 1000UL, NRF_TIMER_
SHORT_COMPARE0_CLEAR_MASK, false);
Each tick of the 1 MHz clock driving Timer0 is 1 µS
long. So, to blink the blue LED every half second, we need
500,000 ticks.
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK is
a macro representing a shortcut. A shortcut is simply a
direct path that is established between a task and event.
In this case, every time Timer0 triggers a compare event, a
shortcut path is used to automatically clear the timer. The
n SCREENSHOT 6B. The Timer driver needs some
Boolean false at the end of the function call disables the
tweaking. As you can see, we have set the timer clock
generation of an interrupt on a Timer0 compare event.
frequency to 1 MHz and set the timer resolution to
Recall that this whole PPI/GPIOTE process is based on
32 bits. Set at 6, this IRQ priority is next to the lowest
task and event addresses being logically connected. We
priority setting of 7.
have already laid the groundwork. Now, let’s build those
56 December 2016