This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART Implementation

I am using Nrf52 DK as a J link programmer to program  Laird BL-652  which is connected to NXP LPC 1519 via RX/TX Pins. I am trying to send commands from BL652 to NXP via UART but the BL652 is some times sending the commands and most of the time its says error. Also there is no response from the NXP. However the UART configurations are same on both NXP and BL652.

Here is my UART function-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void uart_init(void)
{
uint32_t err_code;
{ const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
UART_HWFC,
false,
NRF_UART_BAUDRATE_115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Event Handler-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void uart_error_handle(app_uart_evt_t * p_event)
{
uint8_t value;
uint32_t err_code;
if (p_event->evt_type == APP_UART_DATA_READY)
{
err_code = app_uart_get(&value);
APP_ERROR_CHECK(err_code);
err_code = app_uart_put(value);
APP_ERROR_CHECK(err_code);
}
else if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_communication);
}
else if (p_event->evt_type == APP_UART_FIFO_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_code);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And my write function-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void send_uart(char* cmd)
{
while(app_uart_put(*cmd) == NRF_SUCCESS)
{
cmd++;
SEGGER_RTT_WriteString(0,"Success");
}
}
void nxp_flashing(void)
{
ret_code_t err_code;
int* cmd;
char rsp[5];
uint8_t cr, i;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here is my main.c (mostly copy paste)-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdint.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "boards.h"
#include "app_error.h"
#include "ble.h"
#include "ble_err.h"
#include "ble_hci.h"
#include "ble_srv_common.h"
#include "ble_advdata.h"
#include "ble_conn_params.h"
#include "ble_conn_state.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "app_timer.h"
//#include "app_button.h"
#include "nrf_soc.h"
#include "nrf_strerror.h"
#ifdef SCANNER_ADDED
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Can anyone suggest where I am going wrong and what is the best way to send and receive commands through UART (app_uart_get/put  or somethings else).

Thanks