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

usbd_ble_uart example cannot receive more than 128 bytes from com port when I modify it

Hi all,

I am adapting some examples according to my needs and have encountered something that I find strange. I am trying to send 244 bytes from computer to usbd_ble_uart application on PCA10056 via com port. I am using SDK15.3

The modified code looks like this. I only changed the if statements which decide whether it is time to send the data coming from com port via ble (by using the end of line characters).

case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
        {
            ret_code_t ret;
            static uint8_t index = 0;
            index++;

            do
            {
                if (index == 244)
                {
                    
                        bsp_board_led_invert(LED_CDC_ACM_RX);
                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        NRF_LOG_HEXDUMP_DEBUG(m_cdc_data_array, index);

                        do
                        {
                            uint16_t length = (uint16_t)index;
                            if (length + sizeof(ENDLINE_STRING) < BLE_NUS_MAX_DATA_LEN)
                            {
                                memcpy(m_cdc_data_array + length, ENDLINE_STRING, sizeof(ENDLINE_STRING));
                                length += sizeof(ENDLINE_STRING);
                            }

                            ret = ble_nus_data_send(&m_nus,
                                                    (uint8_t *) m_cdc_data_array,
                                                    &length,
                                                    m_conn_handle);

                            if (ret == NRF_ERROR_NOT_FOUND)
                            {
                                NRF_LOG_INFO("BLE NUS unavailable, data received: %s", m_cdc_data_array);
                                break;
                            }

                            if (ret == NRF_ERROR_RESOURCES)
                            {
                                NRF_LOG_ERROR("BLE NUS Too many notifications queued.");
                                break;
                            }

                            if ((ret != NRF_ERROR_INVALID_STATE) && (ret != NRF_ERROR_BUSY))
                            {
                                APP_ERROR_CHECK(ret);
                            }
                        }
                        while (ret == NRF_ERROR_BUSY);
          

                        index = 0;
                }

                /*Get amount of data transferred*/
                size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm);
                NRF_LOG_DEBUG("RX: size: %lu char: %c", size, m_cdc_data_array[index - 1]);

                /* Fetch data until internal buffer is empty */
                ret = app_usbd_cdc_acm_read(&m_app_cdc_acm,
                                            &m_cdc_data_array[index],
                                            1);
                if (ret == NRF_SUCCESS)
                {
                    index++;
                }
            }
            while (ret == NRF_SUCCESS);

            break;
        }

The problem is that, for the program to enter the if(index == 244) statement, I have to send 244 bytes twice. This problem does not occur if the threshold is 128 bytes or lower. However above 128 bytes I have the this problem. I guess it has something to do with usb sending data in chunks of 64 bytes but I could not figure it out. Zero padding to complete 244 byte to 256 bytes (multiple of 64) did not work either. I have tried it using both RealTerm and PuTTy with the same result

Do you know why this problem occurs and how I can overcome it (preferably by not using the end of line characters)? 

Thanks in advance.

Best regards,

Denin

  • Hello Denin,

    What happens the first time you send 244 bytes? I understand that it doesn't trigger, but can you try to set a breakpoint to see what your index is? (or try to print it using NRF_LOG_INFO()). Does it trigger at all, and what is your index variable?

  • Hello Edvin,

    The output is as follows. I put the NRF_LOG_INFO() commands right before the break. As it can be sen even if I send 244 bytes, RealTerm sends 2 chucks of 64 bytes (128 bytes is cumulative) and then stops. This explains why I have to send the 244 bytes twice. 

    I believe it is because of the serial terminals. I have tried with serial terminals other than the mentioned above. The way they send is different but still not as wanted though. Our developer is working on the computer interface anyways, he will have to make sure that he handles transmission properly. Thanks for your suggestion. 

    Best regards,

    Denin

Related