TWI hard faulting

Been working to get the TWI communicating to a LIS331HH and been having tons of trouble getting it functioning.

I do an init like the example

void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
       .scl                = SCL_PORT,
       .sda                = SDA_PORT,
       .frequency          = NRF_DRV_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_MID,
       .clear_bus_init     = false
    };

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

    nrf_drv_twi_enable(&m_twi);
}

then when i try to do any tx/rx

    ret_code_t err_code;
    uint8_t twidat = 0;
    err_code = nrf_drv_twi_rx(&m_twi,0x18,&twidat,sizeof(twidat));
    APP_ERROR_CHECK(err_code);

following the code by stepping in it goes to this function and hardfaults

__STATIC_INLINE void nrf_twi_int_enable(NRF_TWI_Type * p_reg,
                                        uint32_t       mask)
{
    p_reg->INTENSET = mask;
}

thanks,

Kevin

Parents Reply
  • The hardfault seems to be caused by modifications in the file "salt_lick_firmware\modules\nrfx\mdk\nrf52810_peripherals.h". Reverting this file back to the original from nRF5 SDK v17.1.0 seems to fix the issue.

    Setting TWIM_COUNT to 0 will create an empty array of m_handlers in nrf_drv_twi.c, which makes the TWI interrupt handler trying to call an invalid address. The MDK files should normally not be modified, as this can cause issues like this.

Children
Related