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

Adding UART breaks code's functionality

Hi, I'm learning to use the nrf52832 (PCA10040). I'm on SDK12.2.0 S132.

I've done those basic tutorials while merging codes from the examples. My code can currently read the die temperature and broadcast it via BLE notification every 1 second.

I'm currently trying to merge UART functionality into the code, but have run into some problem.

I've done the following to make the UART initialization code listed at later part to even compile at all.

  1. Added app_uart_fifo.c and retarget.c into nRF_Drivers.

  2. Added app_fifo.c into nRF_Libraries.

  3. Enabled UART_ENABLED , UART0_ENABLED, APP_FIFO_ENABLED, APP_UART_ENABLED, RETARGED_ENABLED in sdk_config.h.

My UART initialization code and relevant parameters are as following.

#define RX_PIN_NUMBER  8
#define TX_PIN_NUMBER  6
#define MAX_TEST_DATA_BYTES     (31U)                /**< max number of test bytes to be used      for tx and rx. */
#define UART_TX_BUF_SIZE 128                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 128                         /**< UART RX buffer size. */


void uart_error_handle(app_uart_evt_t * p_event)
{
    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);
    }
}
const app_uart_comm_params_t comm_params =
  {
      RX_PIN_NUMBER,
      TX_PIN_NUMBER,
      NULL,//RTS_PIN_NUMBER
      NULL,//RTS_PIN_NUMBER
      APP_UART_FLOW_CONTROL_DISABLED,
      false,
      UART_BAUDRATE_BAUDRATE_Baud9600
  };
	
	APP_UART_FIFO_INIT(&comm_params,
                     UART_RX_BUF_SIZE,
                     UART_TX_BUF_SIZE,
                     uart_error_handle,
                     APP_IRQ_PRIORITY_LOW,
                     err_code);	
		
	APP_ERROR_CHECK(err_code);

I've noticed the following issues after initializing UART.

  1. SEGGER_RTT_WriteString and SEGGER_RTT_printf doesn't work in the codes after initialization. (I've also read that NRF_LOG cannot coexist with UART, does that mean I have to comment out all usage of NRF_LOG, and to disable the module in sdk_config?)

  2. I cannot search the dev board in "nRF Connect" anymore.

Any idea how I can fix the issue? The issue doesn't exist if I comment out the APP_UART_FIFO_INIT and the following err check.

Anyway my aim to adding UART is to use the UART to communicate with a GPS module (only RX @ baud rate of 9600 is required), and then parse and process the information before transmitting it to phone via BLE. But I'm trying to get the basic UART functionality to even work at all. I'd be glad if anyone can help me, or even guide me to a better resource regarding what I'm trying to do.

Thanks!

p/s : right after I described my problem, I tried to disable NRF_LOG_BACKEND_UART_INSTANCE, and activated NRF_LOG_BACKEND_SERIAL_USES_RTT instead. But still the UART and the original functionality is not there.

  • FormerMember
    0 FormerMember

    1) Yes, that's correct. There is only one UART on nRF52832, so it can either be used by NRF_LOG or by your application for other purposes. Since you are using the nRF52-DK, you can use logging over RTT instead of UART. By doing so, you free up the UART for your application.

    2) The reason that nRFConnect cannot find your board anymore, is probably because the problem in the code is during the initialization, so the board never starts to advertise. Could you run the chip in debug mode, and check if (and where) it fails in the initialization?

Related