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

How to use NRF51 DK I2C(TWI) with SDK 12.2 with Keil MDK?

I need to connect VL53Xl to NRF51 DK> I am using latest 12.2 SDK with Keil MDK.I cannot find any I2C(TWI) example. I can find examples for NRF52 based devices. but not for NRF51.

I tried using Hal functions but ended up with missing definitions which are only available with NRF52 devices.

Pls help

  • TWI0_USE_EASY_DMA is defined in the sdk_config.h file in the twi_sensor example, but not in the sdk_config.hfile of the ble_app_uart example. You will have to copy the TWI_ENABLED section starting from line 74 to 208 into the sdk_config.h file of the ble_app_uart example.

  • @Bjorn Thanks for the reply. I tested sdk_config.h earlier and ble_app_uart sdk_config.h had the TWI_ENABLED section already. I tested functionality of sdk_config.h by using some #warning and it was observed the TWI ENABLED section is not got executed for some weird reason. I removed definitions check points by directly defining them as below and now compilation is ok. This is bad but I cant find any other issue.

    // <e> TWI_ENABLED - nrf_drv_twi - TWI/TWIM peripheral driver
    //==========================================================
    #ifndef TWI_ENABLED
    #define TWI_ENABLED 0
    #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 
    
    #ifndef TWI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define TWI_DEFAULT_CONFIG_IRQ_PRIORITY 3
    #endif
    
    // <e> TWI0_ENABLED - Enable TWI0 instance
    //==========================================================
    #ifndef TWI0_ENABLED
    #define TWI0_ENABLED 0
     
    #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 0
    #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>
    
    //#endif //TWI_ENABLED
    
  • Did you change the

    #ifndef TWI1_ENABLED
    #define TWI1_ENABLED 0
    

    to

    #ifndef TWI1_ENABLED
    #define TWI1_ENABLED 1 
    

    in the ble_app_uart sdk_config.h file?

  • @Bjorn Thanks, I removed existing TWI section from ble_app_uart sdk_config.h and pasted the same from twi_sensor sdk_config and its compile now. Thank you very much. saved hours.

Related