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

Cannot receive UART data

I'm using the nRF52 DK with SDK 15.3.0. At this point I'm trying to get a UART loop back to work by tying the TX pin (P0.8) to the RX pin (P0.9). I have verified that the RX GPIO is set for an input and the input buffer is connected. My project is based on the "ble_app_uart" project. I see what looks like reasonable data going out on the TX pin but I never get the APP_UART_DATA_READY event in the event handler. I do get the APP_UART_TX_EMPTY event after sending the string of 4 bytes but do not get any other events. I have also tried putting a 50mS delay after sending a byte with "app_uart_put" then calling "app_uart_get" and it returns NRF_ERROR_NOT_FOUND indicating no data to read.

Looking at the UARTE0 registers after sending the data, EVENTS_RXSTARTED is a 1 and EVENTS_RXDRDY and EVENTS_ENDRX are both 0. The ENDRX interrupt is enabled, the RXD PTR is set to an address in RAM, the MAXCNT is 1 and AMOUNT is 0.

Here is my UART initialization code:

void uart_init(void)
{
    uint32_t                     err_code;
	
    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = PIC_TXD_BITNUM,
        .tx_pin_no    = PIC_RXD_BITNUM,
        .rts_pin_no   = 0xffffffff,									/* indicates pin isn't used */
        .cts_pin_no   = 0xffffffff,									/* indicates pin isn't used */
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = NRF_UART_BAUDRATE_115200
    };

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,                            /* 256 byte buffer */
                       UART_TX_BUF_SIZE,                            /* 256 byte buffer */
                       uart_event_handler,
                       APP_IRQ_PRIORITY_LOWEST,
                       err_code);
    APP_ERROR_CHECK(err_code);
}

I get the same results with two nRF52 DK boards. Any ideas?

  • Pin P0.09 is an NFC pin and must be configured to work as an io pin before use as Rx or Tx. Add CONFIG_NFCT_PINS_AS_GPIOS in the Project->Options->Common->Preposseor->Preprocessor Definitions

    This will activate the following one-time code snippet which permanently maps P0.9 and P0.10 as GPIO - see this code in System_nrf52.c

    /

        /* 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

    There are many posts here covering this issue if you need more background

  • Sorry, I didn't think about saying I'm already configuring the NFC pins as GPIO with that same code (with the reset after writing to the UICR). I see 0xfffffffe in the UICR NFCPINS register so that appears to be working.

    Digging a little deeper, before calling "app_uart_init" I have the pin set as input with the input buffer connected and the pull-up enabled. On the scope, I see 0V on the pin. Through the debugger, if I change the pin to an output it is always low even after setting it high so something still isn't right.

    Also, I changed my RX input to P0.05 and now I do get the APP_UART_DATA_READY and the correct data is received. That's isn't an option for my custom board, I still need to get P0.09 to work.

  • I thought you were on custom hardware, but it using the development kit nRF52DK note that R25 and C42 are populated by default, thus loading the pin with 300pF, and that R28 is not connected by default which means that P0.09 doesn't connect to P12, P6 or P17 despite the label. I imagine removing R25 and shorting R27 is what you would have intended .

  • OK, that makes sense. In my haste I didn't notice it was the "P0.09" signal connected to P6 instead of "P0.09/NFC1". The way the schematic is done is less than clear.

    Thanks for the help.

Related