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

nRF52840 Dongle UART

Hello,

I use the Blinky example from the SDK. Now I would like to implement an UART on the nRF52840 Dongle. But the program always stops at either nrf_drv_uart_rx or nrf_drv_uart_tx. Can anyone help me with that?

Thanks in advance!

nrf_drv_uart_t upp_uart_inst = NRF_DRV_UART_INSTANCE(0);

void rm_uart_init()
{
    nrf_drv_uart_config_t vfg = NRF_DRV_UART_DEFAULT_CONFIG;
    cfg.baudrate    = UART_BAUDRATE_BAUDRATE_Baud115200;
    cfg.hwfc        = NRF_UART_HWFC_DISABLED;
    cfg.pselrxd     = 29;
    cfg.pseltxd     = 31;
    cfg.use_easy_dma= 0;
        
    nrf_drv_init(&app_drv_uart_init, &cfg, NULL);
}

void fkt()
{
    uint8_t tx_buffer[0] = 1;
    uint8_t rx_buffer[0] = 0;
    nrf_drv_uart_tx(&app_uart_inst, tx_buffer, 1);
    nrf_drv_uart_rx (&app_uart_inst, rx_buffer, 1);
}

Parents
  • For development, please use an nRF52840 DK. 

    I guess the issue is that you receive a COMMUNICATION_ERROR event, because your UART pins are floating. But you need a programmer to verify this, so that you can debug. 

    The nRF52840 DK has an on board debugger, but the dongle does not. 

    The debugger will allow for debugging and logging.

    It will save you a lot of time. Perhaps it is worth the expense.

    Best regards,

    Edvin

  • Thanks for your answer. 

    The nRF52840 DK uses the pca10056 SDK right? I want to use the Dongle eventually, so even if I have a working programm for the DK, I can't use it on the Dongle. Am I mistaken?

    When the pins are floating, shoudn't I recive and send noise? Why would the code stop at:

    nrf_drv_uart_tx(&app_uart_inst, tx_buffer, 1);
    nrf_drv_uart_rx (&app_uart_inst, rx_buffer, 1);
     

    But could I try to pull TX and RX high, with external restistors?

    Best regards,

    Luca

  • Ok, I just wanted to make 100% sure that you didn't think the pins were routed through the USB port (like it is on the DK). Then I am afraid you need to debug.

  • Alright. I ordered one. Thank you for your help!

  • I did some debugging now on the nRF52840 DK

    uint8_t rx_buffer[1];
    uint8_t tx_buffer[1];
    
    nrf_drv_uart_t app_uart_inst = NRF_DRV_UART_INSTANCE(0);
    
    
    uint32_t rm_uart_put(uint8_t c);
    uint32_t rm_uart_get();
    
    void rm_uart_init() 
    {
        nrf_drv_uart_config_t cfg = NRF_DRV_UART_DEFAULT_CONFIG;
    
        cfg.baudrate              = UART_BAUDRATE_BAUDRATE_Baud115200;
        cfg.hwfc                  = NRF_UART_HWFC_DISABLED;
        cfg.pselrxd               = 26; // 29
        cfg.pseltxd               = 27; // 31
        cfg.use_easy_dma          = false;
     
        ret_code_t err_code;
        //err_code = nrfx_uart_init(&app_uart_inst, &cfg, NULL);
        err_code = nrf_drv_uart_init(&app_uart_inst, &cfg, 0); //Original
        APP_ERROR_CHECK(err_code);
    }
    
    void rm_uart_handle()
    {
        uint32_t err_code;
        uint8_t send = 0;
        uint8_t recive = 1;
    
        err_code = rm_uart_put(send);
    
        recive = rm_uart_get();
    }
    
    
    uint32_t rm_uart_put(uint8_t c) 
    {
        ret_code_t err_code;
        tx_buffer[0] = c;
    
        err_code = nrf_drv_uart_tx(&app_uart_inst, tx_buffer, 1);
        APP_ERROR_CHECK(err_code);
    }
    
    uint32_t rm_uart_get(void) 
    {
        ret_code_t err_code;
    
        err_code = nrf_drv_uart_rx(&app_uart_inst, rx_buffer, 1);
        APP_ERROR_CHECK(err_code);
    
        return *rx_buffer;
    }

    That is the error I get from putting the breakpoint to error_info from the APP_ERROR_CHECK() after the nrf_drv_uart_init function:

    void app_error_handler_bare(unsigned int error_code=0x00000011)

    In the infocenter it says that the error 0x11 is: The length of one or more input arguments was invalid. The first input argument contains:

    app_uart_inst = {inst_idx=x00, uarte={p_reg=0x40002000, drv_inst_idx=0x00}, uart={p_reg=40002000, drv_inst_idx=0x00}}

    When I comment out that line 

        cfg.use_easy_dma          = false;
    
    , I get a 0x08 error instead. I don't if that means anything because I still don't really know what to do with all that.

    The UART Pins are not connected yet and advertising and BLE stuff is commented out.

  • What SDK version do you use, by the way?

    Is it possible to send the project, so that I can try to reproduce it?

    I guess it comes from nrfx_uarte_init() -> 

    nrfx_err_t nrfx_uarte_init(nrfx_uarte_t const *        p_instance,
                               nrfx_uarte_config_t const * p_config,
                               nrfx_uarte_event_handler_t  event_handler)
    {
        NRFX_ASSERT(p_config);
        uarte_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];
        nrfx_err_t err_code = NRFX_SUCCESS;
    
        if (p_cb->state != NRFX_DRV_STATE_UNINITIALIZED)
        {
            err_code = NRFX_ERROR_INVALID_STATE;
            NRFX_LOG_WARNING("Function: %s, error code: %s.",
                             __func__,
                             NRFX_LOG_ERROR_STRING_GET(err_code));
            return err_code;
        }
    
    #if NRFX_CHECK(NRFX_PRS_ENABLED)
        static nrfx_irq_handler_t const irq_handlers[NRFX_UARTE_ENABLED_COUNT] = {
            #if NRFX_CHECK(NRFX_UARTE0_ENABLED)
            nrfx_uarte_0_irq_handler,
            #endif
            #if NRFX_CHECK(NRFX_UARTE1_ENABLED)
            nrfx_uarte_1_irq_handler,
            #endif
            #if NRFX_CHECK(NRFX_UARTE2_ENABLED)
            nrfx_uarte_2_irq_handler,
            #endif
            #if NRFX_CHECK(NRFX_UARTE3_ENABLED)
            nrfx_uarte_3_irq_handler,
            #endif
        };
        if (nrfx_prs_acquire(p_instance->p_reg,
                irq_handlers[p_instance->drv_inst_idx]) != NRFX_SUCCESS)
        {
            err_code = NRFX_ERROR_BUSY;
            NRFX_LOG_WARNING("Function: %s, error code: %s.",
                             __func__,
                             NRFX_LOG_ERROR_STRING_GET(err_code));
            return err_code;        // <-- This line
        }

    Out of curiousity:

    Do you (try to) use logging? Can you send me your sdk_config.h file? What is NRF_LOG_ENABLED and NRF_LOG_BACKEND_UART_ENABLED defined as, if they are present?

  • I got your file from the message.

    First of all, you have a few redefined definitions. LED_3, LED_4. You should make sure that defines like these only have one value. They are already defined in pca10056.h.

    I can't compile the project, because there are a lot of undefined variables and functions. I guess you have some custom files outside the project folder, or that you changed some of the default files in the SDK. Try to compile your project in a new unzipped, unmodified SDK, and you will see.

    However, your project uses the UART as a log backend, so you can't use it in the application. If you need the UART in addition to logging, you need to disable the log, or change to RTT backend.

    I suggest that you change to the following in sdk_config.h:

    #define NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0
    #define NRF_LOG_BACKEND_UART_ENABLED 0

Reply
  • I got your file from the message.

    First of all, you have a few redefined definitions. LED_3, LED_4. You should make sure that defines like these only have one value. They are already defined in pca10056.h.

    I can't compile the project, because there are a lot of undefined variables and functions. I guess you have some custom files outside the project folder, or that you changed some of the default files in the SDK. Try to compile your project in a new unzipped, unmodified SDK, and you will see.

    However, your project uses the UART as a log backend, so you can't use it in the application. If you need the UART in addition to logging, you need to disable the log, or change to RTT backend.

    I suggest that you change to the following in sdk_config.h:

    #define NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 0
    #define NRF_LOG_BACKEND_UART_ENABLED 0

Children
Related