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

How can I use ERR_TO_STR_TWI() macro?

Hello,

I would like to understand how can I make use of the macro ERR_TO_STR_TWI in order to know what error is being given by my TWI module function.

I have tried something like this

  err_code = nrf_drv_twi_rx(&twi, reg_addr, rxData, bytesNumberRx);
  ERR_TO_STR_TWI(err_code);
  APP_ERROR_CHECK(err_code);

But it doesn't work at all, actually setting a breakpoint on ERR_TO_STR_TWI() shows how this call isn't invoked at all...

Any hints?

Thanks in advance

Parents
  • Hello ndarkness

    The ERR_TO_STR_TWI is defined in sdk_errors.h. For it to be defined NRF_LOG_ENABLED must be defined and set to 1. The macro is defined as

    #define ERR_TO_STR_TWI(err_code)        m_sdk_errors_name_twi[err_code - NRF_ERROR_PERIPH_DRIVERS_ERR_BASE]
    

    Where

    #define NRF_ERROR_PERIPH_DRIVERS_ERR_BASE   (0x8200)
    

    and

    const char * m_sdk_errors_name_twi[ERR_NAMES_TWI_SIZE] =
    {
        "NRF_ERROR_DRV_TWI_ERR_OVERRUN",
        "NRF_ERROR_DRV_TWI_ERR_ANACK",
        "NRF_ERROR_DRV_TWI_ERR_DNACK"
    };
    

    So calling ERR_TO_STR_TWI(err_code) alone wouldn't really do much as it just returns the pointer to a string, but doesn't do anything with it.

    You could take the return value and output that using NRF_LOG_INFO(). A quick test

    NRF_LOG_INFO("%s",(uint32_t)ERR_TO_STR_TWI(0x8202));
    

    Outputted the expected result.

    Best regards

    Jørn Frøysa

  • Thanks Jørn, I assume this means that it is not going to be officially supported going forward, and that it is safer not to use the Macros to allow for easier SDK upgrades in the future.

Reply Children
No Data
Related