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

Parents Reply Children
  • 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

  • The final goal would be to have debug output via UART in secure dfu bootloader and still fit in size restrictions. It would be enough to send some characters or strings. Don't need buffering of output. But I want to see which pathes are taken through bootloader or what error conditions occure. I need to see this via UART, because JTAG is not available widely. UART could be possible, if something is not working as planned.
    Note: The above tests were done in application code, just to learn how to deal with UART.

  • Where can I find implementation of NRF_LOG_INFO,

    especially the version which sends something over UART in non-deferred mode?

    Does it enable something (clocks, power, ...) before sending some characters

    and switching it off, when everything was sent out?

Related