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 Children
  • cool example. love the concept but it seems to be just incrementing and counting from 1 to 127. seems to be a similar problem to this guy;

     twi scanner showing random address 

    I'm wondering if it's because we only have 10k pullups..? Is there a way to enable the internal pullups on the sda/scl lines to help this out?

    Also when we start implementing this into our design, is it in your opinion better to just use the twi manager?

    btw thanks again for all the help, really appreciate it Jørgen!

  • cool example. love the concept but it seems to be just incrementing and counting from 1 to 127. seems to be a similar problem to this guy;

     twi scanner showing random address 

    Not sure why that would happen. Have you checked the TWI pins with a logic analyzer? Is one of the pins tied to GND/VDD?

    I'm wondering if it's because we only have 10k pullups..? Is there a way to enable the internal pullups on the sda/scl lines to help this out?

    The internal pull resistors should be enabled by default by the TWI driver. You should normally not need to add external pull resistors.

    Also when we start implementing this into our design, is it in your opinion better to just use the twi manager?

    That depends on your application, and what you will be interfacing. TWI manager is a higher-level library on top of the TWI drivers to easily allow you to change the configuration of the TWI peripheral between transfers, or to schedule more transfers to different devices. If your TWI slaves all support the same configuration, the driver will normally work fine as well.

Related