Can we run software without external clocks.

Hi Team,

currently we are using nrf52833 micro controller for out prototype design. can run micro controller without external 32Mhz and 32khz crystals.

  • Yes.

    However, without the 32MHz crystal, the RADIO peripheral will not be frequency-stable enough to be usefully functional (and might also be illegal).  But as an MCU that doesn't use the radio peripheral, it should work.

  • How to enable both internal clock and external clocks in software, can i have code snipet for this using zephyr

  • Assuming you are using NCS:

    • Build a project, as simple as you wish; for example, "hello world", or "blinky"
    • for the low frequency oscillator, the default build configuration will result in the external (32kHz crystal) oscillator being used.
      • if you do not have an external crystal installed, the code will fail to start and your "main.c" will never execute.  If you run your code under a debugger, you can see where it gets stuck during the startup code
      • if you set "CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y" in your prj.conf, then the internal RC oscillator will be used for the low frequency source.
    • the default build configuration will result in the internal RC oscillator being used for the high frequency clock source
      • if your project uses Bluetooth, the BLE code will turn the crystal on/off as needed by the BLE code
      • if your own code needs the high frequency crystal oscillator to run for your code, you can turn it on/off as needed.  Good luck in finding a definitive single answer from the documentation on how you should do that :-(
        • you can search these forums (use the keyword "HFXO", which means high frequency crystal oscillator) and probably find one or more ways that work for you... and you can look these up in the online Nordic documentation to see how happy you are with the method(s) you have chosen
      • or you can use my code for starting the 32MHz crystal oscillator and keeping it running, which I am pasting in below.  If my code looks ugly and convoluted, and like a lot of pain was incurred and frustration endured in writing this crappy looking piece of code and confirming that it works.... you would be correct.  Hopefully you write better, cleaner, nicer-looking code than that.

    Here is an ugly way to start HFXO that works for me (at least when not using BLE.... haven't tested it with BLE)


    static int clock_setup() {
    	int rc;
    
    // //
    	LOG_INF("nrfx_clock_init(0)");
    	nrfx_clock_init(0);
    	// LOG_INF("nrfx_clock_init(clk_callback)");
    	//  nrfx_clock_init(clk_callback);
    	LOG_INF("nrfx_clock_enable");
    	nrfx_clock_enable();
    	// //   nrfx_clock_hfclk_start(); //  * @note This function is deprecated. Use @ref nrfx_clock_start instead.
    	LOG_INF("nrfx_clock_start");
    	nrfx_clock_start(NRF_CLOCK_DOMAIN_HFCLK);
    	LOG_INF("nrfx_clock_is_running");
    	rc = nrfx_clock_is_running(NRF_CLOCK_DOMAIN_HFCLK,0);
    	LOG_INF("nrfx_clock_is_running=%d",rc);
    // nrf_clock_hf_src_get();
    // sd_clock_hfclk_request();
    
    // // //
    // 	static const struct device *const clock0 = DEVICE_DT_GET_ONE(nordic_nrf_clock);
    // 	if (!device_is_ready(clock0)) {
    // 		return 22;
    // 	}
    
    // 	rc = clock_control_on(clock0, CLOCK_CONTROL_NRF_SUBSYS_HF);
    // 	if (rc) {
    // 		LOG_ERR("clock_control_on failed first try rc=%d",rc);
    // 		rc = clock_control_on(clock0, CLOCK_CONTROL_NRF_SUBSYS_HF);
    // 	}
    // 	// todo: confirm we are running HFXO
    // 	if (rc) {
    // 		LOG_ERR("clock_control_on failed rc=%d",rc);
    // 		return rc;
    // 	}
    
    	// struct onoff_manager *clk_mgr;
    	// // struct onoff_client clk_cli;
    
    	// clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
    	// // mpsl_clock_hfclk_request();
    
    
    
            // // what about logging?
           	// LOG_ERR("Good morning!!"); // only need to add header files; CONFIG_LOG=y already set
            // printk("after LOG... but it it?\n");
    	return 0;
    }
    

  • Thanks for reply,

    can you suggest how to enable internal high-speed clock frequency alone using zephyr

  • The internal HFCLK will be enabled automatically when needed. But as  says, you will not be able to use the radio peripheral running on this. 

Related