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

TWI Clearing Bus with NRFX_TWI driver

Hello,

We are using the NRFX_TWI driver which we understand is a new and improved version of the legacy NRF_DRV_TWI driver.  However we are getting a number of apparent stuck-bus errors if our app breaks in the wrong place, and have to completely remove power from the system to get everything un-stuck (simply restarting the code does not help).

It appears this is a common problem and the solution given in https://devzone.nordicsemi.com/f/nordic-q-a/21508/twi-stuck-bus-recovery seems to be simple enough.  However I cannot find an analog for the NRFX_TWI driver, as this is not a valid parameter in the config_t struct:

static const nrfx_twi_config_t twi_config = {
.scl = TWI_SCL,
.sda = TWI_SDA,
.frequency = NRF_TWI_FREQ_400K,
//.clear_bus_init=true, //does not work
.interrupt_priority = TWI_DEFAULT_CONFIG_IRQ_PRIORITY};

Could you advise as to how to clear the bus?

Thanks!

--Allen

  • Hi Allen,

    As I understand it, NRFX drivers are not the replacement for nrf_drv.

    We want to use the same hal layer over different solutions we have so that the underlying hal layer is not implemented in different ways in different solutions.

    So the nrf_drv_twi API is still the same, the change is that now it uses nrfx_twi below it.

    And in SDK15 you still have the same API for nrf_twi and you still have the clear_bus_init option.

    Now assuming that you know all the above, if you say that the clear_bus_init option is not working. then I am little confused as this option just uses the gpio set clear option and it has not changed at all.

        if(p_config->clear_bus_init)
        {
            /* Send clocks (max 9) until slave device back from stuck mode */
            twi_clear_bus(p_config);
        }

  • Hi Aryan,

    I'm currently in the same position, porting to SDK15 and ran into that issue. As I understood, the nrfx drivers are the replacement for nrf_drv ones. In fact, as I understand it, the nrf_drv drivers don't exist anymore, and in the new SDK there's only a translation layer, that translates calls to the old API into calls to the new nrfx API.

    Can you explain what is that piece of code that you posted? Where did you get it from? Thanks for your help!

  • Aryan,

    As with Andy's reply, I also do understand it that the nrfx drivers are the replacement.  That certainly seems to be how they are described in the documentation.  The "nrf_drv" calls in SDK15 are the wrapper, but the underlying layer is now nrfx.  

    I think you are right that if we continue to use the nrf_drv wrappers (although the recommendation is to stop using them) we can use the p_config->clear_bus_init property to clear the bus on init.  But it appears that the nrf_drv wrappers will be deprecated at a certain point.

    @Andy what I did for my project was just copy the twi_clear_bus function into the nrfx_twi.c file, calling it nrfx_twi_clear_bus.  Then when I am going to call nrfx_twi_init() I first call nrfx_twi_clear_bus().  I could have instead put that call into the nrfx_twi_init function, but that would have required modifying the config structure.  

    I suspect / hope this will be included in nrfx_drv_twi in a future release.

    Best,

    --Allen

  • > I suspect / hope this will be included in nrfx_drv_twi in a future release.

    @Allen, will pass this info to the team. Thanks.

Related