This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C with Softdevice nrf_drv_twi_enable hangs

Using SDK 12.1.0

I2C with SoftDevice works on PCA10040 Eval Board with nRF52832 but hangs in the nrf_drv_twi_enable function with TY module EBSGCNZWY which is an nRF51822 version F1. Running without the SoftDevice on the TY module, the I2C works fine.

  • There is no reason why the nrf_drv_twi_enable(..) function should hang unless the ASSERT macro is used. Can you check if this is the case? Right click on ASSERT and choose "go to definition", if it is defined as a while(1) or assert_nrf_callback(..) then this might be the reason it hangs.

    Then the problem is that you have not initialized the twi module before you called nrf_drv_twi_enable(..).

  • ASSERT is defined as

    #define ASSERT(expr) //!< Assert empty when disabled
    

    Same code works on the nRF52832/S132 but not with nRF51822/S130. Doesn't that mean the TWI module was initialized correctly? Thanks.

  • Just took a look at the datasheet of the module. It says there that it uses a 32MHz clock instead of 16MHz which is used on the nRF51 DK. Have you set the XTALFREQ to 32MHz or configured the UICR register for 32MHz? See this relevant post.

    I did not find out if the module uses a 32KHz crystal, but from the size of the module I would guess not. You have configured the SoftDevice to use 32 KHz RC oscillator? See nrf_clock_lf_cfg_t passed in the SOFTDEVICE_HANDLER_INIT macro/function.

  • Using the following from the TY DataSheet:

    The evaluation board included with the Nordic Development Kit uses a 16MHz clock. Therefore the sample code from Nordic is designed to be used with a 16MHz clock. On the other hand, the EYSGCN series module uses a 32MHz system clock, making it incompatible with the Nordic sample code (i.e. sample code does not configure HFCLK: XTALFREQ register for 32MHz). To fix this issue, we need to write the value 0xFFFFFF00 to the UICR (User Information Configuration Register) at address 0x10001008. Please note that the UICR is erased whenever you download a SoftDevice. The UICR can be written by using the debug tools:

    nrfjprog.exe --snr <your_jlink_debugger_serial_number> --memwr 0x10001008 --val 0xFFFFFF00

  • Here are some more data points on this issue:

    running peripheral/twi_scanner using s132/pca10040 returns output of

     0> APP:INFO:TWI scanner.
     0> APP:INFO:TWI device detected at address 0x53.
    

    running peripheral/twi_sensor with the 0x53 address found from running twi_scanner returns output of

     0> APP:INFO:
     0> TWI sensor example
     0> APP:INFO:
     0> handler 1 
    

    indicating the device address is nacked.

Related