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

Is it possible to use P0.00 and P0.01 for I2C? I'm using RTC for LFCLK, so I thought these would be available as GPIO.

I've designed a custom board for the NRF52832. Current consumption is not a major concern, and the pin location was convenient, so I wanted to use P0.00 and P0.01 for I2C. I've set the LFCLK to the RTC, and so I thought it would be OK to use those pins. My application gets hung up though when trying to use them. Setting I2C to use different pins resolves that issue, but would require a board redesign. Can I use P0.00 and .01 for I2C? Is some other configuration necessary?

Parents
  • Worth checking the settings, have a look at this code:

        // 32kHz Osc pins can be used as GPIOs or 32kHz Oscillator, special case
        if ( (PinId == RCC_OSC_OUT_PIN) && (NRF_CLOCK->LFCLKSRC & 0x000001) ) return "RTC-OSC-OUT";
        if ( (PinId == RCC_OSC_IN_PIN)  && (NRF_CLOCK->LFCLKSRC & 0x000001) ) return "RTC-OSC-IN";
    

    Typically the pins are set to RTC mode by functions invoked by this:

        // Configure RTC
        lfclk_config();
    
    __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
    {
        NRF_CLOCK->LFCLKSRC =
            (uint32_t)((source << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
    }
    

Reply
  • Worth checking the settings, have a look at this code:

        // 32kHz Osc pins can be used as GPIOs or 32kHz Oscillator, special case
        if ( (PinId == RCC_OSC_OUT_PIN) && (NRF_CLOCK->LFCLKSRC & 0x000001) ) return "RTC-OSC-OUT";
        if ( (PinId == RCC_OSC_IN_PIN)  && (NRF_CLOCK->LFCLKSRC & 0x000001) ) return "RTC-OSC-IN";
    

    Typically the pins are set to RTC mode by functions invoked by this:

        // Configure RTC
        lfclk_config();
    
    __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
    {
        NRF_CLOCK->LFCLKSRC =
            (uint32_t)((source << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
    }
    

Children
  • I'm using the Arduino core in PlatformIO, but following your suggestion I added this during configuration and it is now working. clockState and clockSource are temporary global variables I can watch in the debugger as I don't have UART connected. I can see the clock source change, although the clock never starts even though the start trigger shows up. I then can communicate with the I2C device.

    if (clockState) {
          NRF_CLOCK->TASKS_LFCLKSTOP = 1;
          while(NRF_CLOCK->LFCLKSTAT);
        }
        clockState = NRF_CLOCK->LFCLKSTAT;
        clockSource = NRF_CLOCK->LFCLKSRCCOPY;
        NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC;  
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        clockRun = NRF_CLOCK->LFCLKRUN;
        while(!NRF_CLOCK->LFCLKSTAT);
        clockState = NRF_CLOCK->LFCLKSTAT;
        clockSource = NRF_CLOCK->LFCLKSRCCOPY;
       }

Related