This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Serial library event handler example

Hi,

Does anyone have a complete example of using an event handler to read UART data set up with the serial library? This post is the only incomplete example I can find. The example program sets _ev_handler to NULL in the setup NRF_SERIAL_CONFIG_DEF

OR my devices needs to constantly read continuous incoming UART data, so does someone have the best practice on reading the serial so the buffer doesn't overflow? Thanks

Parents
  • This works in SDK 15:

    static void serial_rx_cb(struct nrf_serial_s const *p_serial, nrf_serial_event_t event) {
        if (event == NRF_SERIAL_EVENT_RX_DATA) {
            char c;
            APP_ERROR_CHECK(nrf_serial_read(&serial_uart, &c, sizeof(c), NULL, 500));
            APP_ERROR_CHECK(nrf_serial_write(&serial_uart, &c, sizeof(c), NULL, 500));
            //__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%c\n", c);
        }
    }

    But it is still char by char. I don't know how to use it properly with a bigger SERIAL_BUFF_RX_SIZE?

Reply
  • This works in SDK 15:

    static void serial_rx_cb(struct nrf_serial_s const *p_serial, nrf_serial_event_t event) {
        if (event == NRF_SERIAL_EVENT_RX_DATA) {
            char c;
            APP_ERROR_CHECK(nrf_serial_read(&serial_uart, &c, sizeof(c), NULL, 500));
            APP_ERROR_CHECK(nrf_serial_write(&serial_uart, &c, sizeof(c), NULL, 500));
            //__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%c\n", c);
        }
    }

    But it is still char by char. I don't know how to use it properly with a bigger SERIAL_BUFF_RX_SIZE?

Children
No Data
Related