Hi ,
I am using the example "ble_app_uart".
I enable uart while receiving data from nus handler and turn it off after transmitting.
After I mondified the code, it can't transmit data through UART.
But If I enable the uart peripheral while power on and never turn it off, it can work.
Is there any suggestion to fix this problem?
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
uint8_t tmp_Status;
if(uart_status == 0 )
{
tmp_Status = 0;
uart_init();
}
for(uint16_t tmp = 0 ; tmp<0xFF ; tmp++);
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
uint32_t err_code;
NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
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(tmp_Status == 0)
{
uart_status = 0;
app_uart_close();
}
}