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.

Parents Reply
  • Hey Edvind,

    Sorry for the late response. After modifying the project for the board PCA10059 the example works fine. I am receiving the string "Timeout number: x" where x is the number of timeouts of the timer you set starting at 0. No anomalies in how I receive the text.

    I tested sending UART data on a different dev-kit, the CC3220S Launch XL  from Texas Instruments. I experienced the same problem where if is send data as soon as the port is opened, every character is interpreted as if it had "\n\r" behind it. This problem stops however after the initial message (on startup) is sent, so i guess it has something to do with either micro-controller startup, drivers or puTTY. It is not a real problem and since waiting 0.1 sec before sending the initial message solves my problems I wont spend anymore time on it.

    Thanks for the help and the quick replies!

    Nick

Children
No Data
Related