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

UART not working on custom board

Hi,

We have developed a custom board using nrf52832 chip and currently everything like (BLE, TWI, ADC etc) is working fine but we are having issues with the UART. we have changed the RX and TX pins to following for custom board

UART_TX_PIN       9
UART_RX_PIN       8

and we are using app_uart.c 

Pins are configured like this

// UART PINS
    nrf_gpio_pin_dir_set(UART_TX_PIN, NRF_GPIO_PIN_DIR_OUTPUT);
    nrf_gpio_pin_write(UART_TX_PIN, 0);

    nrf_gpio_pin_dir_set(UART_RX_PIN, NRF_GPIO_PIN_DIR_INPUT);

and the following code is used for the initialization of the UART

uint32_t err_code;
// Initialize control variables in serial_library.c
Init_Uid_Packet();

nrf_gpio_cfg_input(RX_PIN, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_output(TX_PIN);

APP_UART_FIFO_INIT(&comm_params, 
RX_BUF_SIZE,
TX_BUF_SIZE,
Uart_Evt_Callback,
UART_IRQ_PRIORITY,
err_code);

APP_ERROR_CHECK(err_code);

it seems that the UART initializes correctly and when we try to send anything over UART there is no activity over the Uart_Evt_Callback(). I have listed the code of this below,

static void Uart_Evt_Callback(app_uart_evt_t * uart_evt)
{   
    char cr;
    switch (uart_evt->evt_type)
    {
        case APP_UART_DATA: 
            //Step1: Data is ready on the UART
            while(app_uart_get(&cr) != NRF_SUCCESS);
            // Send each character to rfid reader submodule function

            //Step2: Passing byte to Rfid module
            Pass_String(cr);  
            #if defined(DEBUG)
              SEGGER_RTT_printf(0, "One Char : %c \n",cr);
            #endif

            #if defined(TEST)
              app_sched_event_put(&cr, (sizeof(&cr) * 1), Uart_Evt_Callback_scheduler);
            #endif 
        break;
                        
        case APP_UART_DATA_READY:
            //Data is ready on the UART FIFO 
              //Step1: Data is ready on the UART
            while(app_uart_get(&cr) != NRF_SUCCESS);
            // Send each character to rfid reader submodule function

            //Step2: Passing byte to Rfid module
            Pass_String(cr);  
            #if defined(DEBUG)
              SEGGER_RTT_printf(0, "One Char : %c \n",cr);
            #endif

            #if defined(TEST)
              app_sched_event_put(&cr, (sizeof(&cr) * 1), Uart_Evt_Callback_scheduler);
            #endif 
        break;
                        
        case APP_UART_TX_EMPTY:
            //Data has been successfully transmitted on the UART
            #if defined(DEBUG)
              SEGGER_RTT_printf(0, "Data successfully sent on UART \n");
            #endif
        break;

        case APP_UART_FIFO_ERROR:          //An error in the FIFO module used by the app_uart module has occured
            #if defined(DEBUG)
              SEGGER_RTT_printf(0, "FIFO error \n");
            #endif
        break;

        case APP_UART_COMMUNICATION_ERROR: // An communication error has occured during reception.
            #if defined(DEBUG)
              SEGGER_RTT_printf(0, "UART COMM Error \n");
            #endif
        break;
                        
        default:
        break;
    }  
}

I also have tested the UART pins by applying the saleae logic analyzer on the RX TX pins but there was no activity over the pins when I try to send/receive anything from there.

Please look into this issue I have debugged a lot by comparing the UART example too but did not found a solution.

Thanks,

  • Pin 9 may be set as an NFC pin; add CONFIG_NFCT_PINS_AS_GPIOS in the project preprocessor definitions. The following code runs in system_nrf52.c on startup and will do a one-time configure of the pin:

        /* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined,
           two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as
           normal GPIOs. */
        #if defined (CONFIG_NFCT_PINS_AS_GPIOS)
            if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; // Write Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk;
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; // Read-only Enable
                while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
                // UICR changes require a reset to be effective
                NVIC_SystemReset();
            }
        #endif

  •   This was the exact thing that I was missing

    Thank you so much! :) 

Related