Hi, I use nRF52840, with SDK 15.3.0
I would like to toggle LED every time receive 1 byte to UART.
So I wrote down the code.
static void ppi_init()
{
uint32_t err_code;
uint32_t uart_event_addr;
uint32_t gpio_task_addr;
nrf_ppi_channel_t ppi_channel_uart_gpio_toggle;
err_code = nrf_drv_ppi_init();
if((err_code != 0) && (err_code != NRF_ERROR_MODULE_ALREADY_INITIALIZED))
{
APP_ERROR_CHECK(err_code);
}
nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
err_code = nrf_drv_gpiote_out_init(LED_pin, &config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_alloc(&ppi_channel_uart_gpio_toggle);
APP_ERROR_CHECK(err_code);
uart_event_addr = nrfx_uart_event_address_get(&uart1_inst, NRF_UART_TASK_STARTRX);
gpio_task_addr = nrfx_gpiote_out_task_addr_get(LED_pin);
err_code = nrfx_ppi_channel_assign(ppi_channel_uart_gpio_toggle, uart_event_addr, gpio_task_addr);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_enable(ppi_channel_uart_gpio_toggle);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_task_enable(LED_pin);
}
Thanks in advance!