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

USB CDC ACM sending one byte at a time SDK V16

I'm using the USB CDC ACM example to write a message to a com port. I can receive messages fine except there is one problem. I am receiving the characters one character at a time. For example, I am sending: "This is a welcome message!\r\n" to the terminal. The message I receive is as follows:
T
h
i
... and so on.

This is the code I am using in the while loop:

while (true)
    {
        while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }
        if(welcome_flag)
        {
            size_t size = sprintf(m_tx_buffer, "This is a welcome message!\r\n");
            //nrf_delay_ms(20);
            ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
            if (ret == NRF_SUCCESS)
            {
                welcome_flag = 0;
            }
        }
        if(m_send_flag)
        {
            static int  frame_counter;

            size_t size = sprintf(m_tx_buffer, "Hello USB CDC FA demo: %u\r\n", frame_counter);

            ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
            if (ret == NRF_SUCCESS)
            {
                ++frame_counter;
            }
        }

        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
        /* Sleep CPU only if there was no interrupt since last loop processing */
        __WFE();
    }
}

Interestingly if I delay between sprintf() and app_usbd_cdc_acm_write() I receive the message correctly. The button also sends the message correctly. Removing check if(ret == NRF_SUCCES) has no effects.

Lastly I am using Linux Mint 19.3 and SES V4.52.

Related