Using I2C & GPIOTE interrupt with soft device enabled

jjdelorme gravatar image

asked 2014-02-13 19:01:23 +0200

updated 2014-02-13 19:01:36 +0200

Hi - I wanted to post for the chance it may help others in the future. I'll spare everyone the drama, but I've been stuck on this issue for days and have finally resolved through the help of a few different messages on this forum and my goal here is to bring them together in the context of my resolution.

Background I have an I2C component that separately signals an interrupt when there is data to read (an accelerometer). I have GPIOTE enabled for the interrupt line and I use I2C to then read the data.

I could read the device fine during initialization using I2C and I could receive the interrupt fine, but upon receiving the interrupt I could not reach in and read the data on the device using I2C, it would continually end up in the Hardfault_Handler.

PPI & Soft Device I2C is accomplished by using the TWI and the SDK provides a hardware implementation (twi_hw_master.c) which uses PPI. I have the soft device (S310) enabled and it is documented (shame on me for not reading) in several places that PPI is restricted when the soft device is enabled. Several posts identified this as a potential problem when I discovered I was hard faulting here:

tw_hw_master.c:99 NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_STOP

I found the resolution for this documented here. The resolution was to change all NRF_PPI calls to sd_ppi_* calls after the soft device was enabled.

GPIOTE IRQ Priority One problem solved, but still crashing with hard fault and in the SAME place, but now it was when I was calling sd_ppi_channel_assign(...). It turns out that my problem was described here. The GPIOTE Interrupt handler provided by the SDK in app_gpiote.c was running at HIGH, which was higher than the SVCALL used by sd_ppi_channel_assign and this was creating the hard fault. The fix for this problem was to change app_gpiote.c:161 to a lower priority:


.... Sigh of relief... All is now working. I hope this helps someone and avoids unnecessary grumpiness to one's spouse or co-workers :-)!

edit retag flag offensive close delete report spam


This is an amazing help. Can you share your updated tw_hw_master.c file with the appropriate sd_ppi_* calls swapped in? Maybe on github? I feel like this is something nordic should provide with each SDK release.

la-ble ( 2014-12-05 22:43:39 +0200 )editconvert to answer

4 answers

Sort by » oldest newest most voted
olha gravatar image

answered 2014-02-17 15:53:07 +0200

updated 2014-03-07 12:10:43 +0200

Thanks for posting this write-up! I'd just like to highlight one thing: The usage of the PPI in the TWI implementation is actually due to item 36 in the PAN for nRF51822 or this PAN for nRF51422:

The following shortcuts are not implemented: • Short-cut between BB event and SUSPEND task. • Short-cut between BB event and STOP task.

As shown in the PAN document, this have been fixed on the second revision chips (nRF51822 FA, or nRF51422 E0 and later), and hence, if you use and target such chips, you can instead use the shortcuts directly, without using the PPI at all. This should save you both the PPI channels and some hassle.

edit flag offensive delete publish link more

You can refer to this example for how twi_hw_master can be modified to use the shorts: https://github.com/NordicSemiconductor/nrf51-ble-app-lbs/tree/twi-display-5.1.0

Ole Morten ( 2014-03-11 15:56:59 +0200 )editconvert to answer
jjdelorme gravatar image

answered 2014-03-07 01:28:44 +0200

Thanks for the tip, Ole. I'm just getting around to looking into this. What portion of the chip identification can tell me if the revision is FA or higher? On my sample chips I have:

N51422 QFAAE0 1347AA

Thank you!

edit flag offensive delete publish link more

Sorry, you didn't write which chip you were using, so I assumed nRF51822. For the nRF51422, the equivalent version to FA is your E0. You can refer to this PCN: https://www.nordicsemi.com/eng/nordic/download_resource/26303/1/9501341 Also, for the nRF51422, you should use this PAN, not the one I originally linked to (although all hardware problems are the same): https://www.nordicsemi.com/eng/nordic/Products/nRF51422/nRF51422-PAN/26307

Ole Morten ( 2014-03-07 11:37:57 +0200 )editconvert to answer
jjdelorme gravatar image

answered 2014-03-07 13:11:52 +0200

Great, thank you.

edit flag offensive delete publish link more
nicewook gravatar image

answered 2016-04-26 06:55:32 +0200

Thanks a lot. It was great help.

also I didnot get what Ole Morten means. Means we don't need ppi in twi anymore to newest chip?

edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools

1 follower


Asked: 2014-02-13 19:01:23 +0200

Seen: 3,230 times

Last updated: Apr 26 '16