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

nRF52840 USB CDC RX event only triggered on every other byte received

Hi. In the nRF52840 SDK example USBD_CDC, the APP_USBD_CDC_ACM_USER_EVT_RX_DONE event only seems to fire every other byte that is sent through. E.g. If i send one character from putty the event doesn't trigger, but then on the second character it fires and so on. My test LED in the code below only toggles when two bytes have been received.

This will be ok for messages that are a multiple of 2 in length, but no good for messages I send with an odd number of bytes, as the last byte will be lost.

Is there a setting somewhere to change this, or is there a mistake somewhere?

Thanks

 * */
static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                    app_usbd_cdc_acm_user_event_t event)
{

    size_t size = 0;

    app_usbd_cdc_acm_t const * p_cdc_acm = app_usbd_cdc_acm_class_get(p_inst);

    switch (event)
    {
        case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN:
        {
            bsp_board_led_on(LED_CDC_ACM_OPEN);

            /*Setup first transfer*/
            size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm);
            ret_code_t ret = app_usbd_cdc_acm_read(&m_app_cdc_acm,
                                                   m_rx_buffer,
                                                   READ_SIZE);
            UNUSED_VARIABLE(ret);
            break;
        }
        case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE:
            bsp_board_led_off(LED_CDC_ACM_OPEN);
            break;
        case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:
            bsp_board_led_invert(LED_CDC_ACM_TX);
            break;
        case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
        {
            nrf_gpio_pin_toggle(16);
            break;
        }
    }
}

Parents Reply Children
No Data
Related