<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to check nRF52840 external low frequency crystal (32kHz) is connected or not?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53362/how-to-check-nrf52840-external-low-frequency-crystal-32khz-is-connected-or-not</link><description>Hi, 
 
 Using SDK 15.2.0 and SD S140_6_1_1. 
 I have two hardware of nRF52840, one has external LF crystal(32kHz) and another does not. 
 Want to run same firmware file in both hardware so Is there any way to detect external crystal is connected or not</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Oct 2019 08:46:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53362/how-to-check-nrf52840-external-low-frequency-crystal-32khz-is-connected-or-not" /><item><title>RE: How to check nRF52840 external low frequency crystal (32kHz) is connected or not?</title><link>https://devzone.nordicsemi.com/thread/215658?ContentTypeID=1</link><pubDate>Fri, 18 Oct 2019 08:46:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fd9a01d-f237-40cc-b103-25415cfeb8be</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Good idea!&lt;br /&gt;Adding some lines that are needed in some toolchains:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;

*/  Synchronize register writes to 16MHz AHB clock by reading the same register. *
*   Protect against out of order execution by explicitly casting to volatile.    */
(volatile void)NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED; 

NRF_CLOCK-&amp;gt;LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
for (int cnt=0; cnt&amp;lt;LFXO_TIMEOUT; cnt++)
    if (NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED) break;
if (! NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED) {
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTOP = 1;
    // maybe wait some time here
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
    
    */  Synchronize register writes to 16MHz AHB clock by reading the same register. *
    *   Protect against out of order execution by explicitly casting to volatile.    */
    (volatile void)NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED; 

    NRF_CLOCK-&amp;gt;LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
}
while (! NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED) ;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check nRF52840 external low frequency crystal (32kHz) is connected or not?</title><link>https://devzone.nordicsemi.com/thread/215657?ContentTypeID=1</link><pubDate>Fri, 18 Oct 2019 08:43:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d0d0738-4049-439a-93d7-ff9d983c646d</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Great suggestion Dmitry! I&amp;#39;ve updated my previous reply to better reflect what&amp;#39;s possible and not.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check nRF52840 external low frequency crystal (32kHz) is connected or not?</title><link>https://devzone.nordicsemi.com/thread/215560?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2019 14:07:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12505c9e-f0a4-45a4-897f-8aa2ea97ae77</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;if you want to use a single firmware for both boards, you can write some flag to UICR that will indicate whether LFXO is installed. If this way is inconvenient for your case, just start LFXO and wait for 0.25 sec, then check if it&amp;#39;s not started, switch to RC:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK-&amp;gt;LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
for (int cnt=0; cnt&amp;lt;LFXO_TIMEOUT; cnt++)
    if (NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED) break;
if (! NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED) {
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTOP = 1;
    // maybe wait some time here
    NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK-&amp;gt;LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC &amp;lt;&amp;lt; CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK-&amp;gt;TASKS_LFCLKSTART = 1;
}
while (! NRF_CLOCK-&amp;gt;EVENTS_LFCLKSTARTED) ;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to check nRF52840 external low frequency crystal (32kHz) is connected or not?</title><link>https://devzone.nordicsemi.com/thread/215517?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2019 12:35:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f77aab18-1ab7-4730-a319-65b62e708cf3</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Nirav&lt;/p&gt;
&lt;p&gt;You can not dynamically switch between clocks during operation. By default, all our SDK examples are set to use the external LF crystal, but you can easily switch to the internal RC or synthesized LF clock by editing the following parameters in your sdk_config.h file: &lt;strong&gt;NRFX_CLOCK_CONFIG_LF_SRC&lt;/strong&gt;, &lt;strong&gt;CLOCK_CONFIG_LF_SRC&lt;/strong&gt;, and&amp;nbsp;&lt;strong&gt;NRF_SDH_CLOCK_LF_SRC&lt;/strong&gt;(if you use the SoftDevice).&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>