Hi i am developing a project on custom board with mcu as nRF52833 module. This board needs to communicate with GPS module and Sim Module, so I need to use 2 UART ports to communicate with them. I used UART DMA with 2 functions uart_event_handler and uart_config then i can communicate with my GPS module but when i duplicate these 2 functions and edit pins TX, RX => (uart_event_handler2 and uart_config2) give second UART port to communicate with sim module but I am not able to communicate with any device. I only communicate with GPS or Sim Module when enable either uart_config function in main (uart_config for GPS, uart_config2 for sim module), it wont work with any device if i enable both configuration. add here my code. please help me. I've been stuck with this problem for a week :((((. Thank you very much
void uart_event_handler(app_uart_evt_t * p_event)
{
static uint8_t data_array[100];
static uint8_t index = 0;
//uint8_t index = 0;
uint32_t err_code;
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
app_uart_get(&data_array[index]);
index++;
if ((data_array[index - 1] == '\n') || (data_array[index - 1] == '\r') )
{
if (index > 1)
{
printf("received %s\n",data_array);
memset(data_array, 0, sizeof(data_array));
}
index = 0;
}
break;
// check if some communication error occured, this event will be trigered
case APP_UART_COMMUNICATION_ERROR:
// Check the reason of error by accessing the error variable and then pass it to error handler
APP_ERROR_HANDLER(p_event->data.error_communication);
break;
// check if fifo error occured, this might be fifo overflow or other relevant errors
case APP_UART_FIFO_ERROR:
// Check the reason of error by accessing the error variable and then pass it to error handler
APP_ERROR_HANDLER(p_event->data.error_code);
break;
case APP_UART_TX_EMPTY:
// toggle an led or use any other function here
nrf_gpio_pin_toggle(led);
default:
break;
}
}
void uart_config(void)
{
uint32_t err_code; // a variable to hold error value
const app_uart_comm_params_t comm_params = // a struct that will hold all the uart configurations
{
RX_PIN_NUMBER1, // Mention the Pin number for RX pin
TX_PIN_NUMBER1, // Mention the Pin number for TX pin
RTS_PIN_NUMBER, // Mention the Pin number for RTS pin
CTS_PIN_NUMBER, // Mention the Pin number for CTS pin
APP_UART_FLOW_CONTROL_DISABLED, // Disable the hardware flow control, we only need it if we are using high baud rates, we can save some pins by disabling this
false, // event parity if true, if false no parity
NRF_UARTE_BAUDRATE_9600 // make sure to write NRF_UARTE_BAUDRATE_115200 and not the NRF_UART_BAUDRATE_115200
};
APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_event_handler, APP_IRQ_PRIORITY_LOWEST, err_code);
APP_ERROR_CHECK(err_code); // check if some error occured during initialization
}
void uart_event_handler2(app_uart_evt_t * p_event)
{
static uint8_t data_array[100];
static uint8_t index = 0;
uint32_t err_code;
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
app_uart_get(&data_array[index]);
index++;
if ((data_array[index - 1] == '\n') || (data_array[index - 1] == '\r') )
{
if (index > 1)
{
printf("received %s\n",data_array);
memset(data_array, 0, sizeof(data_array));
}
index = 0;
}
break;
// check if some communication error occured, this event will be trigered
case APP_UART_COMMUNICATION_ERROR:
// Check the reason of error by accessing the error variable and then pass it to error handler
APP_ERROR_HANDLER(p_event->data.error_communication);
break;
// check if fifo error occured, this might be fifo overflow or other relevant errors
case APP_UART_FIFO_ERROR:
// Check the reason of error by accessing the error variable and then pass it to error handler
APP_ERROR_HANDLER(p_event->data.error_code);
break;
case APP_UART_TX_EMPTY:
// toggle an led or use any other function here
nrf_gpio_pin_toggle(led);
default:
break;
}
}
void uart_config2(void)
{
bsp_board_led_on(1);
uint32_t err_code; // a variable to hold error value
const app_uart_comm_params_t comm_params = // a struct that will hold all the uart configurations
{
RX_PIN_NUMBER2, // Mention the Pin number for RX pin
TX_PIN_NUMBER2, // Mention the Pin number for TX pin
RTS_PIN_NUMBER, // Mention the Pin number for RTS pin
CTS_PIN_NUMBER, // Mention the Pin number for CTS pin
APP_UART_FLOW_CONTROL_DISABLED, // Disable the hardware flow control, we only need it if we are using high baud rates, we can save some pins by disabling this
false, // event parity if true, if false no parity
NRF_UARTE_BAUDRATE_115200 // make sure to write NRF_UARTE_BAUDRATE_115200 and not the NRF_UART_BAUDRATE_115200
};
APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_event_handler2, APP_IRQ_PRIORITY_LOWEST, err_code);
APP_ERROR_CHECK(err_code); // check if some error occured during initialization
}
int main(void)
{
// call the uart configuration function and now wait for the events from the uart
//uart_config();
uart_config2();
// infinite loop
while (true)
{
}
}
