Hi,
Iam working on a nrf52840 and trying to achieve data flow from BLE device using NUS and transfer this data through UART.Uart is configured as (TX:P1.01,RX:P1.02).Iam receiving data in
nus_data_handler, and expecting app_uart_put will send data to TX which can be received by UART connected device RX.I can see that data is looping back to sender.Iam using NUS added
ble_peripheral\ble_app_template
static void uart_init(void) {
uint32_t err_code;
app_uart_comm_params_t const comm_params =
{
// .rx_pin_no = RX_PIN_NUMBER,
// .tx_pin_no = TX_PIN_NUMBER,
.rx_pin_no = NRF_GPIO_PIN_MAP(1, 1),
.tx_pin_no = NRF_GPIO_PIN_MAP(1, 2),
.rts_pin_no = RTS_PIN_NUMBER,
.cts_pin_no = CTS_PIN_NUMBER,
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
.use_parity = false,
#if defined(UART_PRESENT)
.baud_rate = NRF_UART_BAUDRATE_115200
#else
.baud_rate = NRF_UARTE_BAUDRATE_115200
#endif
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_event_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
APP_ERROR_CHECK(err_code);
}
static void nus_data_handler(ble_nus_evt_t *p_evt) {
ret_code_t ret_val;
if (p_evt->type == BLE_NUS_EVT_RX_DATA) {
uint32_t err_code;
NRF_LOG_INFO("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)
;
}
} else if (p_evt->type == BLE_NUS_EVT_TX_RDY) {
flag_transmitted = 1;
NRF_LOG_INFO("TX OK");
} else if (p_evt->type == BLE_NUS_EVT_COMM_STARTED) {
NRF_LOG_INFO("BLE_NUS_EVT_COMM_STARTED");
//TODO : add send START command if required
// SendData();
flag_connected = 1;
}
}
Please advice whether and how can I use this.
Thanks
Syam