Hello ,
I am using freertos with nrf uart service, i could able to get these timings that seem little bit weird.
one of the pin toggled for each successful ble_nus_data_send , and other pin toggled for each BLE_NUS_EVT_TX_RDY event.
After every 5 pulses (2.9ms for each) , i have a big gap (33.65ms for each) . And TX_RDY pulses are very long too. I created a task to send the data .
Question : How can i avoid 33.65ms gap ?
Here is my send task ;
xTaskCreate(send_ble_task_function, "BLESEND", configMINIMAL_STACK_SIZE + 200, NULL,1, &m_ble_send_task_handle));
static void send_ble_task_function (void * pvParameter) { ret_code_t err_code; int k = 0; nrf_gpio_cfg_output(15); nrf_gpio_cfg_output(16); UNUSED_PARAMETER(pvParameter); for(int i = 0 ;i<247;i++) { data_arrayx[i] = i; } while (true) { if(command){ do { nrf_gpio_pin_write(15,1); err_code = ble_nus_data_send(&m_nus, data_arrayx, &m_ble_nus_max_data_len, m_conn_handle); if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_RESOURCES) && (err_code != NRF_ERROR_NOT_FOUND)) { APP_ERROR_CHECK(err_code); } nrf_gpio_pin_write(15,0); data_arrayx[2] = (char)k++; } while (err_code != NRF_ERROR_RESOURCES); data_arrayx[2] = (char)k--; ulTaskNotifyTake(pdTRUE,1000); } else{ vTaskSuspend(m_ble_send_task_handle);} }
And i am signalling my task in this routine ;
static void nus_data_handler(ble_nus_evt_t * p_evt) { int srtCmpResult = 0; if (p_evt->type == BLE_NUS_EVT_RX_DATA) { uint32_t err_code; srtCmpResult = strncmp(p_evt->params.rx_data.p_data,"Start\r",p_evt->params.rx_data.length); if(srtCmpResult == 0 ) { command = 1;vTaskResume(m_ble_send_task_handle);} srtCmpResult = strncmp(p_evt->params.rx_data.p_data,"Stop\r",p_evt->params.rx_data.length); if(srtCmpResult == 0 ) { command = 0;} for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++) { do { err_code = app_uart_put(p_evt->params.rx_data.p_data[i]); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) { NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code); APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_BUSY); } if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r') { while (app_uart_put('\n') == NRF_ERROR_BUSY); } } if (p_evt->type == BLE_NUS_EVT_TX_RDY) { nrf_gpio_pin_write(16,1); nrf_gpio_pin_write(16,0); xTaskNotifyGive( m_ble_send_task_handle ); } }
Here is some settings ;
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) /**< Minimum acceptable connection interval (0.4 seconds). */
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) /**< Maximum acceptable connection interval (0.65 second). */