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

Trying to send something over UART

Hello,

I am trying to send something by my own via UARTE0. This is only for testing/learning purposes:

    uint32_t enable0 = NRF_UART0->ENABLE;
    NRF_LOG_INFO("enable(UART0)=%d", enable0);

#if 1
    {
        uint8_t hello_world[] = "Hello\r\n";

        // Configure transmit buffer and start the transfer
        NRF_UARTE0->TXD.MAXCNT = sizeof(hello_world);
        NRF_UARTE0->TXD.PTR = (uint32_t)&hello_world[0];
        NRF_UARTE0->TASKS_STARTTX = 1;

        // Wait until the transfer is complete
        while (NRF_UARTE0->EVENTS_ENDTX == 0)
        {
        }
        // Stop the UART TX
        NRF_UARTE0->TASKS_STOPTX = 1;
        // Wait until we receive the stopped event
        while (NRF_UARTE0->EVENTS_TXSTOPPED == 0);
    }
#endif // 0

    uint32_t pseltxd0 = NRF_UART0->PSELTXD;
    uint32_t pselrxd0 = NRF_UART0->PSELRXD;

    NRF_LOG_INFO("pseltxd(UART0)=%d pselrxd(UART0)=%d", pseltxd0, pselrxd0);

    enable0 = NRF_UART0->ENABLE;
    NRF_LOG_INFO("enable(UART0)=%d", enable0);

This is what I see:

[00:00:00.000,000] <info> app: enable(UART0)=8
[00:00:00.000,000] <info> app: pseltxd(UART0)=7 pselrxd(UART0)=-1
[00:00:00.000,000] <info> app: enable(UART0)=8

I see NRF_LOG_INFO output before and also afterwards. I have ...DEFERRED off.

Do I need something else to send over NRF_UARTE0?

Many thanks!

Best regards,

Marie

  • You should see the UART waveform with an oscilloscope on P0.07.

    You want to set BAUDRATE register. If this is on an NRF DK, the "serial port" (in the Jlink chip) runs at 115200 Baud.

    You also mix NRF_UART0 and NRF_UARTE0 - the enable register is the same, but you really should always use NRF_UARTE0 instead.

    Also make sure that P0.07 is configured as "GPIO output" and set to HIGH. See Pin confiiguration in the UARTE chapter of PS.

  • I thought, when using NRF_LOG_INFO before and afterwards, and output is working,

    the pin, clock settings and baudrate is already ok for my code in between?

  • Whatever I try, UARTE0 or UART0, nothing is sent out by my code :-(

        NRF_LOG_INFO("Just before while endless loop 4711");
    
    #define  UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */
    
        NRF_UARTE0->PSEL.TXD = UART_PIN_DISCONNECTED;
        NRF_UARTE0->PSEL.RXD = UART_PIN_DISCONNECTED;
    
        {
            NRF_UART0->ENABLE = 0;
    
            NRF_UART0->PSELTXD = 7;
            NRF_UART0->PSELRXD = 8;
    
            // Configure baud rate and parity.
            NRF_UART0->BAUDRATE = (115200 << UART_BAUDRATE_BAUDRATE_Pos);
    
            NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
    
            NRF_UART0->ENABLE        = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
            NRF_UART0->EVENTS_RXDRDY = 0;
            NRF_UART0->EVENTS_TXDRDY = 0;
    
            NRF_UART0->CONFIG       &= ~(UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
    
            NRF_UART0->PSELRTS       = UART_PIN_DISCONNECTED;
            NRF_UART0->PSELCTS       = UART_PIN_DISCONNECTED;
    
            NRF_UART0->TASKS_STARTTX = 1;
            NRF_UART0->TASKS_STARTRX = 1;
    
            // Enable UART interrupt
            NRF_UART0->INTENCLR = 0xffffffffUL;
    
            NRF_UART0->TXD = 'A';
            NRF_UART0->TXD = 'B';
            NRF_UART0->TXD = 'C';
        }
    
        while(1);
    

  • The DK header files for PCA10040 and PCA10056 list the TXD pin as 6 and not 7. What hardware do you use?

  • I have my own hardware. It sends out data via TxD on pin 7.

    NRF_LOG_INFO is sent out, I see it. Also log output shows pseltxd(UART0)=7

Related