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

Calling nrf_drv_twi_init with a NULL context gives a app_error_fault_handler

I created a TWI software module which runs well as standalone. Now I need to put together with BLE code to comunicate with Android APP. I'm stucked because when I initiate the driver, by calling nrf_drv_twi_init, software craches jumping to function app_error_fault_handler.

My function to initialise TWI:

void twi_init (void)
{
ret_code_t err_code;

if (!nrf_drv_gpiote_is_init())
{
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
}
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIG_READER_SCL_PIN, &out_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_gpiote_out_init(PIG_READER_SDA_PIN, &out_config);
APP_ERROR_CHECK(err_code);

const nrf_drv_twi_config_t twi_bq24155_config = {
.scl = PIG_READER_SCL_PIN,
.sda = PIG_READER_SDA_PIN,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = true
};

err_code = nrf_drv_twi_init(&m_twi, &twi_bq24155_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&m_twi);
}

Code is running on PCA10040, nRF5_SDK_17.0.2_d674dde

What I'm doing wrong?

Parents
  • Thank you Karl,

    Since I'm working with NUS need to compile and replicate the problem with another case, CTS.

    I'm also working with Eclipse, a bit different but could get following log:

    <info> app_timer: RTC: initialized.

    <info> app: Current Time service client started.

    <info> TWIM: Function: nrfx_twim_init, error code: NRF_SUCCESS.

    <info> TWIM: Instance enabled: 0.

    <info> TWIM: Transfer type: XFER_TX.

    <info> TWIM: Transfer buffers length: primary: 1, secondary: 0.

    <warning> TWIM: Function: nrfx_twim_xfer, error code: NRF_SUCCESS.

    <error> app: Fatal error

    The problem is not with nrf_drv_twi_init function but when initialize a transfer, in function nrfx_twim_xfer.

    Put log level to debug but result is the same.

    BR

    Paulo

  • Thank you Karl,

    I didn't any modifications in CTS, just the required to add TWI module.

    I made more investigations and conclude most probably the problem is not  on TWI but in a timer used for internal machine state.

    I created this function:

    /**
     * @brief Function for timing bq24155 controller application entry.
     */
    void bq24155_timer_init(void)
    {
        uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
        uint32_t time_ticks;
        uint32_t err_code = NRF_SUCCESS;
    
        //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        err_code = nrf_drv_timer_init(&TIMER_BQ24155, &timer_cfg, timer_bq24155_event_handler);
        APP_ERROR_CHECK(err_code);
    
        time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_BQ24155, time_ms);
    
        nrf_drv_timer_extended_compare(
             &TIMER_BQ24155, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    }

    Code is running function nrfx_timer_init until the print of NRFX_LOG_INFO which fails on return of nrf_strerror_get (file nrf_strerror.c). Got this running step by step.

    Let me know if you have more information.

    BR

    Paulo

Reply
  • Thank you Karl,

    I didn't any modifications in CTS, just the required to add TWI module.

    I made more investigations and conclude most probably the problem is not  on TWI but in a timer used for internal machine state.

    I created this function:

    /**
     * @brief Function for timing bq24155 controller application entry.
     */
    void bq24155_timer_init(void)
    {
        uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
        uint32_t time_ticks;
        uint32_t err_code = NRF_SUCCESS;
    
        //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        err_code = nrf_drv_timer_init(&TIMER_BQ24155, &timer_cfg, timer_bq24155_event_handler);
        APP_ERROR_CHECK(err_code);
    
        time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_BQ24155, time_ms);
    
        nrf_drv_timer_extended_compare(
             &TIMER_BQ24155, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    }

    Code is running function nrfx_timer_init until the print of NRFX_LOG_INFO which fails on return of nrf_strerror_get (file nrf_strerror.c). Got this running step by step.

    Let me know if you have more information.

    BR

    Paulo

Children
  • Hello Paulo,

    Paulo Arede said:

    I didn't any modifications in CTS, just the required to add TWI module.

    I made more investigations and conclude most probably the problem is not  on TWI but in a timer used for internal machine state.

    I created this function:

    Which timer instance did you use for this?
    Please know that the SoftDevice uses TIMER0, and you may therefore not use it for anything else in your application. If this is the case, please change to use a TIMER instance not already in use elsewhere in the application.

    Best regards,
    Karl

Related