Hi,
I am trying to toggle one pin via PPI when receiving event on another pin - code snippet below:
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_drv_timer.h"
#include "nrf_drv_ppi.h"
#include "nrf_drv_gpiote.h"
#include "bsp.h"
#include "boards.h"
#include "app_error.h"
#include "nrf_gpio.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#define INPUT_PIN BSP_BUTTON_0
#define OUTPUT_PIN 13
static int number_of_events = 0;
static nrf_ppi_channel_t m_ppi_channel1;
static void gpiote_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t polarity)
{
number_of_events++;
NRF_LOG_INFO("number_of_events = %0d", number_of_events);
}
static void gpiote_init(void)
{
ret_code_t err_code;
nrf_drv_gpiote_out_config_t config_out = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
nrf_drv_gpiote_in_config_t configH2L = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
configH2L.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_gpiote_in_init(INPUT_PIN, &configH2L, gpiote_event_handler);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_gpiote_out_init(OUTPUT_PIN, &config_out);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(INPUT_PIN, true);
nrf_drv_gpiote_out_task_enable(OUTPUT_PIN);
}
static void ppi_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel1);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel1,
nrf_drv_gpiote_in_event_addr_get(INPUT_PIN),
nrf_drv_gpiote_out_task_addr_get(OUTPUT_PIN));
APP_ERROR_CHECK(err_code);
}
int main(void)
{
ret_code_t err_code;
static int count = 0;
err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
gpiote_init();
ppi_init();
while (1)
{
}
}
While debugging I receive following messages:
<info> app: Allocated channel: 0.
<info> app: Function: nrfx_ppi_channel_alloc, error code: NRF_SUCCESS.
<info> app: Assigned channel: 0, event end point: 40006100, task end point: 40006004.
<info> app: Function: nrfx_ppi_channel_assign, error code: NRF_SUCCESS.
which means that PPI was configured correctly.
I can also see that events are detected from the message in gpiote_event_handler:
<info> app: number_of_events = 1
<info> app: number_of_events = 2
<info> app: number_of_events = 3
<info> app: number_of_events = 4
However the output pin is not changing its state.
What am I missing?