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