How can I implement UART RX PPI with GPIO?

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!

Parents
  • Hello,

    You are retrieving the task address here:

    uart_event_addr = nrfx_uart_event_address_get(&uart1_inst, NRF_UART_TASK_STARTRX);

    while it should have been

    uart_event_addr = nrfx_uart_event_address_get(&uart1_inst, NRF_UART_EVENT_RXDRDY);

    Hope this helps.

    Best regards,

    Vidar

    .

  • Hi, I appreciate to your reply.

    Let me go back to second question.

    I tried UARTE but It cause matter to system that I designed.

    As, is there any answer use UART peripheral?

    The matter is when I receive one byte, just LED toggle once. And receive next one byte, there's no response to LED.

    Plz check the code below.

    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(0);
        
                err_code = nrf_drv_gpiote_out_init(LED_1, &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_EVENT_RXDRDY);
                gpio_task_addr = nrfx_gpiote_out_task_addr_get(LED_1);
                
                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);
        
                nrfx_gpiote_out_task_enable(LED_1);
    }

    Best regards,

    William.

Reply
  • Hi, I appreciate to your reply.

    Let me go back to second question.

    I tried UARTE but It cause matter to system that I designed.

    As, is there any answer use UART peripheral?

    The matter is when I receive one byte, just LED toggle once. And receive next one byte, there's no response to LED.

    Plz check the code below.

    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(0);
        
                err_code = nrf_drv_gpiote_out_init(LED_1, &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_EVENT_RXDRDY);
                gpio_task_addr = nrfx_gpiote_out_task_addr_get(LED_1);
                
                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);
        
                nrfx_gpiote_out_task_enable(LED_1);
    }

    Best regards,

    William.

Children
No Data
Related