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

Issue including hardware peripherals to a project with softdevice loaded. TWI master communication issue.

Hello,

I have program w/o using softdevice to drive an LED driver using I2C. I was able to get this to work very well with out a softdevice, however once I loaded a soft device, the program gets stuck in a while loop.

In order to get out of the while loop a handler is used when a xfer is complete to flip a flag. I have my code attached, any help or direction would be greatly appreciated. 

Parents
  • Relevant code here is 

    main.c - lines 319 - 335; lines 380-410; called upon in line 1023

    I2C wrapper.c - lines 31 - 88

  • Hi,

    I was able to get this to work very well with out a softdevice, however once I loaded a soft device, the program gets stuck in a while loop.

     Is the while loop in your code, or is it inside the Softdevice? Also, are you able to check if you receive any NRF_DRV_TWI_EVT_ADDRESS_NACK or NRF_DRV_TWI_EVT_DATA_NACK in your callback?

    Thanks,

    Vidar

    edit: I would also have considered changing the interrupt priority of TWI to APP_IRQ_PRIORITY_LOWEST to be aligned with the other SDK modules. 

  • Is that while loop shown in the code you uploaded here? Have you tried changing the interrupt priority?

  • Yes, it is under I2C wrapper. c line 80 

    I lowered the priority and it is still stuck. I even had to to the highest priority?

    Should I change the frequency?

    My twi config is on main.c  lines 380-410

  • The frequency should be fine. Do you have access to a scope or logic analyzer so you can see if any data is being transferred at all? I think it's a bit strange that the callback is not getting called.

  • Seems like the data doesn't transfer at all....

    I stepped through the code and don't any clock of data cycle when 

    err_code = nrf_drv_twi_tx(&I2C_twi_master, ptrDevice, m_txbuf, sizeof(m_txbuf), nostop);

    is written

  • This is in I2C wrapper.c line 57

Reply Children
  • Is it possible that one or both TWI pins are being overridden by BSP,etc?  Do you see the same if you comment this line in main(): buttons_leds_init(). Can you read-back the pin configuration when you're stuck in the while loop?

  • I see the same when everything in int main() is commented out. Only soft device is loaded. I have verified the functionality of the chip with out a softdevice loaded. Any similar issues youve encountered in the past? I also have raised the priority to 3

  • How can I read back the pin config?

  • after nrf_drv_twi_tx; err_code is returned as 0x0000; what does that mean?

  • State of Pins: TCK: 0, TDI: 0, TDO: 0, TMS: 1, TRES: 1, TRST: 1

    is this pin config?