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

  • Hi Kyle,

    The specific macros for converting error codes to strings doesn't seem to be described in the documentation. The macros are not present in the sdk_error.h file in any other version before, or after 12.2 and 12.3. My guess is it was an idea to implement them, which was later abandoned.

Reply Children
No Data
Related