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

How to configure TWI to avoid higher current consumption when using TWI and GPIOTE

In project ,i use a TWI transaction manager to control two sensor devices.So, each device requires a GPIO to detect input interrupts. I use a GPIOTE IN event and a GPIOTE PORT event.According to errata [89],Static 400 µA current while using GPIOTE.

I recofig TWI before i use.Now, the current consumption is back to normal. But only one sensor can enter the interrupt normally.

I don't know why the PROT EVENT GPIO can't enter interrupt.Both sensors work properly without reconfiguring the TWI.

Thanks.

  • Hi,

    This thread describe for instance how to setup port or in event:
    https://devzone.nordicsemi.com/f/nordic-q-a/24391/port-event-vs-nrf_drv_gpiote_in_init 

    There is also a description on how to setup several pins for port events in the thread.

    Best regards,
    Kenneth

     

  • Thank your reply.

    I still have a question. In the errata[89],it indicate the triggered conditions is following:

    • GPIOTE is configured in event mode
    • TWIM/SPIM utilizes EasyDMA

    But ,I only use TWI mode,EasyDMA is closed.Why  is it still triggered?

    Thank you again.

  • What SDK version are you using, and can you send me your sdk_config.h file?

    Best regards,
    Kenneth

  • The SDK version is 13.10, the Soc is 52832.

    How can I send the file to you?

    The following is partial configuration about TWI mode:

    // <e> TWIS_ENABLED - nrf_drv_twis - TWIS peripheral driver
    //==========================================================
    #ifndef TWIS_ENABLED
    #define TWIS_ENABLED 0
    #endif
    #if  TWIS_ENABLED
    // <o> TWIS_DEFAULT_CONFIG_ADDR0 - Address0 
    #ifndef TWIS_DEFAULT_CONFIG_ADDR0
    #define TWIS_DEFAULT_CONFIG_ADDR0 0
    #endif
    
    // <o> TWIS_DEFAULT_CONFIG_ADDR1 - Address1 
    #ifndef TWIS_DEFAULT_CONFIG_ADDR1
    #define TWIS_DEFAULT_CONFIG_ADDR1 0
    #endif
    
    // <o> TWIS_DEFAULT_CONFIG_SCL_PULL  - SCL pin pull configuration
     
    // <0=> Disabled 
    // <1=> Pull down 
    // <3=> Pull up 
    
    #ifndef TWIS_DEFAULT_CONFIG_SCL_PULL
    #define TWIS_DEFAULT_CONFIG_SCL_PULL 0
    #endif
    
    // <o> TWIS_DEFAULT_CONFIG_SDA_PULL  - SDA pin pull configuration
     
    // <0=> Disabled 
    // <1=> Pull down 
    // <3=> Pull up 
    
    #ifndef TWIS_DEFAULT_CONFIG_SDA_PULL
    #define TWIS_DEFAULT_CONFIG_SDA_PULL 0
    #endif
    
    // <o> TWIS_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef TWIS_DEFAULT_CONFIG_IRQ_PRIORITY
    #define TWIS_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <q> TWIS0_ENABLED  - Enable TWIS0 instance
     
    
    #ifndef TWIS0_ENABLED
    #define TWIS0_ENABLED 0
    #endif
    
    // <q> TWIS1_ENABLED  - Enable TWIS1 instance
     
    
    #ifndef TWIS1_ENABLED
    #define TWIS1_ENABLED 0
    #endif
    
    // <q> TWIS_ASSUME_INIT_AFTER_RESET_ONLY  - Assume that any instance would be initialized only once
     
    
    // <i> Optimization flag. Registers used by TWIS are shared by other peripherals. Normally, during initialization driver tries to clear all registers to known state before doing the initialization itself. This gives initialization safe procedure, no matter when it would be called. If you activate TWIS only once and do never uninitialize it - set this flag to 1 what gives more optimal code.
    
    #ifndef TWIS_ASSUME_INIT_AFTER_RESET_ONLY
    #define TWIS_ASSUME_INIT_AFTER_RESET_ONLY 0
    #endif
    
    // <q> TWIS_NO_SYNC_MODE  - Remove support for synchronous mode
     
    
    // <i> Synchronous mode would be used in specific situations. And it uses some additional code and data memory to safely process state machine by polling it in status functions. If this functionality is not required it may be disabled to free some resources.
    
    #ifndef TWIS_NO_SYNC_MODE
    #define TWIS_NO_SYNC_MODE 0
    #endif
    
    // <e> TWIS_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef TWIS_CONFIG_LOG_ENABLED
    #define TWIS_CONFIG_LOG_ENABLED 0
    #endif
    #if  TWIS_CONFIG_LOG_ENABLED
    // <o> TWIS_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef TWIS_CONFIG_LOG_LEVEL
    #define TWIS_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> TWIS_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef TWIS_CONFIG_INFO_COLOR
    #define TWIS_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> TWIS_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef TWIS_CONFIG_DEBUG_COLOR
    #define TWIS_CONFIG_DEBUG_COLOR 0
    #endif
    
    #endif //TWIS_CONFIG_LOG_ENABLED
    // </e>
    
    #endif //TWIS_ENABLED
    // </e>
    
    // <e> TWI_ENABLED - nrf_drv_twi - TWI/TWIM peripheral driver
    //==========================================================
    #ifndef TWI_ENABLED
    #define TWI_ENABLED 1
    #endif
    #if  TWI_ENABLED
    // <o> TWI_DEFAULT_CONFIG_FREQUENCY  - Frequency
     
    // <26738688=> 100k 
    // <67108864=> 250k 
    // <104857600=> 400k 
    
    #ifndef TWI_DEFAULT_CONFIG_FREQUENCY
    #define TWI_DEFAULT_CONFIG_FREQUENCY 26738688
    #endif
    
    // <q> TWI_DEFAULT_CONFIG_CLR_BUS_INIT  - Enables bus clearing procedure during init
     
    
    #ifndef TWI_DEFAULT_CONFIG_CLR_BUS_INIT
    #define TWI_DEFAULT_CONFIG_CLR_BUS_INIT 0
    #endif
    
    // <q> TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT  - Enables bus holding after uninit
     
    
    #ifndef TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT
    #define TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT 0
    #endif
    
    // <o> TWI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef TWI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define TWI_DEFAULT_CONFIG_IRQ_PRIORITY 7
    #endif
    
    // <e> TWI0_ENABLED - Enable TWI0 instance
    //==========================================================
    #ifndef TWI0_ENABLED
    #define TWI0_ENABLED 1
    #endif
    #if  TWI0_ENABLED
    // <q> TWI0_USE_EASY_DMA  - Use EasyDMA (if present)
     
    
    #ifndef TWI0_USE_EASY_DMA
    #define TWI0_USE_EASY_DMA 0
    #endif
    
    #endif //TWI0_ENABLED
    // </e>
    
    // <e> TWI1_ENABLED - Enable TWI1 instance
    //==========================================================
    #ifndef TWI1_ENABLED
    #define TWI1_ENABLED 1
    #endif
    #if  TWI1_ENABLED
    // <q> TWI1_USE_EASY_DMA  - Use EasyDMA (if present)
     
    
    #ifndef TWI1_USE_EASY_DMA
    #define TWI1_USE_EASY_DMA 0
    #endif
    
    #endif //TWI1_ENABLED
    // </e>
    
    // <e> TWI_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef TWI_CONFIG_LOG_ENABLED
    #define TWI_CONFIG_LOG_ENABLED 0
    #endif
    #if  TWI_CONFIG_LOG_ENABLED
    // <o> TWI_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef TWI_CONFIG_LOG_LEVEL
    #define TWI_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> TWI_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef TWI_CONFIG_INFO_COLOR
    #define TWI_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> TWI_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef TWI_CONFIG_DEBUG_COLOR
    #define TWI_CONFIG_DEBUG_COLOR 0
    #endif
    
    #endif //TWI_CONFIG_LOG_ENABLED
    // </e>
    
    // <q> TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED  - Enables nRF52 anomaly 109 workaround for TWIM.
     
    
    // <i> The workaround uses interrupts to wake up the CPU by catching
    // <i> the start event of zero-frequency transmission, clear the 
    // <i> peripheral, set desired frequency, start the peripheral, and
    // <i> the proper transmission. See more in the Errata document or
    // <i> Anomaly 109 Addendum located at https://infocenter.nordicsemi.com/
    
    #ifndef TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED
    #define TWIM_NRF52_ANOMALY_109_WORKAROUND_ENABLED 0
    #endif
    
    #endif //TWI_ENABLED
    // </e>
    

    In this project, I only use TWI0.

    Thanks your reply.

  • Esten,

    I had same issue with you. I used GPIOTE, didn't start TWI with DMA, but still faced with 400uA current issue.

    On the other hand, I have tried the workaround presented in the errata[89], the current indeed is reduced, but compared with the case of GPIOTE being disabled, it will cause ~6uA additional current.

    That is to say, the workaround can reduce the current to some level, in my case it is from 400uA to ~6uA, the workaround isn't so perfect.

      

Related