Hi everyone! I want to work with two UART interfaces in my nRF52DK, in one hand, I must receive data sended by one cable which converts USB to serial, for this I use this code, and the reception is OK, but I have problems to send data to other device.
void cable_event_handler(app_uart_evt_t * p_event){
if(p_event -> evt_type == APP_UART_DATA_READY){
app_uart_get(&response[i]);
//process the response
}
}
void init_cable_uart(void){
const app_uart_comm_params_t comm_params ={
CABLE_RX_PIN,
CABLE_TX_PIN,
NULL,
NULL,
APP_UART_FLOW_CONTROL_DISABLED ,
false,
UART_BAUDRATE_BAUDRATE_Baud9600
};
APP_UART_FIFO_INIT(&comm_params,
RX_BUF_SIZE,
TX_BUF_SIZE,
cable_event_handler,
APP_IRQ_PRIORITY_LOW,
error
);
app_uart_flush();
i = 0;
eof = false;
sof = false;
cmd = false;
act = false;
}
In the other hand I must process the received data. Then, I have to comunicate with other device via UART (first sending the processed data an wait for its response), so, when the reception is finished, I close the UART using this command:
app_uart_close();
Then I open a nev UART interface, with diferent pins, baudrate and event handler:
void cr95hf_event_handler(app_uart_evt_t * p_event){
if(p_event -> evt_type == APP_UART_DATA_READY){
app_uart_get(&response[i]);
//process the response
}
}
void init_cr95hf_uart(void){
const app_uart_comm_params_t comm_params ={
CR95HF_RX_PIN,
CR95HF_TX_PIN,
NULL,
NULL,
APP_UART_FLOW_CONTROL_DISABLED ,
false,
UART_BAUDRATE_BAUDRATE_Baud57600
};
APP_UART_FIFO_INIT(&comm_params,
RX_BUF_SIZE,
TX_BUF_SIZE,
cr95hf_event_handler,
APP_IRQ_PRIORITY_LOW,
error
);
app_uart_flush();
i = 0;
eof = false;
sof = false;
cmd = false;
act = false;
}
So, in resume, when I want to receive data via the serial cable, I open a new UART interface, then I process the received data, and finally I close the UART.
To send to the other device the data I just recived via the serial cable, I open a different UART interface for this device, I send the data and wait to receive the response, then I close the first UART interface.
The problem is that I can't send data to the device after I received the data via the serial cable. What I'm doing wrong? Can the nRF52 handle tho diferent UART interfaces? (I mean two different RX and TX pins, different baud rates, etc...) thank you all!!