<?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>Determining charged and charging on custom board with nrf5340</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/122932/determining-charged-and-charging-on-custom-board-with-nrf5340</link><description>I&amp;#39;m still new to this but particularly in regards to battery. I have a custom board with a nrf5340 and have been working on reading the voltage. I used the battery sample for testing, which seems to be working, though I&amp;#39;m not sure I have it configured</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 17 Sep 2025 21:01:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/122932/determining-charged-and-charging-on-custom-board-with-nrf5340" /><item><title>RE: Determining charged and charging on custom board with nrf5340</title><link>https://devzone.nordicsemi.com/thread/549094?ContentTypeID=1</link><pubDate>Wed, 17 Sep 2025 21:01:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c87531a2-834a-48fa-9acb-1a0456dd14e0</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi lcj,&lt;/p&gt;
&lt;p&gt;Our apologies for the late follow-up.&lt;/p&gt;
&lt;p&gt;I am a little unclear about the physical setup here.&lt;/p&gt;
&lt;p&gt;It seems that previously, Susheel assumed that&amp;nbsp;the Charging and Charged signal on P0.05 and P0.06 are digital. Are they digital? Or are they analog signals?&lt;/p&gt;
&lt;p&gt;What charger are you working with? Do you have a schematic?&lt;/p&gt;
[quote user="lcj"]&lt;blockquote&gt;&lt;p&gt;add CONFIG_REGULATOR=y&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I see it needs a regulator-name based on the build error I&amp;#39;m getting. Will that change the behavior?&lt;/p&gt;[/quote]
&lt;p&gt;What build error are you having? Could you share the full build log, and the relevant source file or snippet?&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Determining charged and charging on custom board with nrf5340</title><link>https://devzone.nordicsemi.com/thread/548652?ContentTypeID=1</link><pubDate>Sat, 13 Sep 2025 15:31:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc0dfe63-f3b1-4c1c-80d7-2e4c9f56b76d</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;It seems strange I need to create a custom binding for something which is probably very common, right?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Determining charged and charging on custom board with nrf5340</title><link>https://devzone.nordicsemi.com/thread/548200?ContentTypeID=1</link><pubDate>Tue, 09 Sep 2025 10:51:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc967efd-2a77-4a8c-bb22-eaece739eddc</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;Do you have any code to show how to:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;br /&gt;Use straightforward HIGH/LOW GPIO reads (and interrupts, if you like) for charger events.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Do I need to do what the other article recommends with the&amp;nbsp;&amp;#39;compatible&amp;#39; property and:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;br /&gt;add CONFIG_REGULATOR=y&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I see it needs a regulator-name based on the build error I&amp;#39;m getting. Will that change the behavior?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
    gpio_power_pin: gpio-power-pin {
        compatible = &amp;quot;regulator-fixed&amp;quot;;
        regulator-name = &amp;quot;gpio_pwr&amp;quot;;
        enable-gpios = &amp;lt;&amp;amp;gpio0 10 GPIO_ACTIVE_HIGH&amp;gt;;
        regulator-boot-on;
    };

};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;How do I set up the overlay/dts&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt;&amp;nbsp; with pins P0.04 and P0.05 to accomplish what you said:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;br /&gt;&lt;span&gt;For charging status your application can tread the charger IC&amp;rsquo;s two pins, CHG and STAT as digital signals rather than analog inputs.The CHG pin lights up whenever your charger is actually pumping current into the battery. The STAT pin becomes on once the battery is full or the charger has gone idle. You just need to connect CHG to P0.05 and STAT to P0.06 on the nRF5340, add a pull-up to 3.3 V and set them up as normal digital inputs.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Determining charged and charging on custom board with nrf5340</title><link>https://devzone.nordicsemi.com/thread/547981?ContentTypeID=1</link><pubDate>Sat, 06 Sep 2025 16:58:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8d2adb7-1f4c-4039-a890-351407837fa1</guid><dc:creator>lcj</dc:creator><description>&lt;p&gt;Whoa.&amp;nbsp;Ok. Maybe a little over my head. Let me see if we can breatk it down. I got reading working in an example with this in the dts:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;adc {
    status = &amp;quot;okay&amp;quot;; // Ensure the ADC controller is enabled

    #address-cells = &amp;lt;1&amp;gt;; // Required for defining child nodes
    #size-cells = &amp;lt;0&amp;gt;;    // Required for defining child nodes

    channel@0 { // Defines the hardware properties for ADC channel 0
        reg = &amp;lt;0&amp;gt;;
        // CRITICAL: Verify this matches the physical pin your battery divider is on
        // AIN0 typically maps to P0.04 on nRF52/nRF53
        zephyr,input-positive = &amp;lt;NRF_SAADC_AIN0&amp;gt;;
        zephyr,gain = &amp;quot;ADC_GAIN_1_6&amp;quot;;       // Adjust gain based on your voltage range
        zephyr,reference = &amp;quot;ADC_REF_INTERNAL&amp;quot;; // Or &amp;quot;ADC_REF_VDD_1_4&amp;quot; if your sample uses that
        zephyr,acquisition-time = &amp;lt;ADC_ACQ_TIME_DEFAULT&amp;gt;;
        zephyr,resolution = &amp;lt;12&amp;gt;; // 12-bit resolution for nRF SAADC
    };

     
    // Use this for ADC testing and set CONFIG_DJ_TEST_CHARGING_ADC=y in the prj.conf
    channel@1 { // For Charged ADC -&amp;gt; Configure for P0.05
        reg = &amp;lt;1&amp;gt;;
        zephyr,input-positive = &amp;lt;NRF_SAADC_AIN1&amp;gt;; // Alternative syntax
        zephyr,gain = &amp;quot;ADC_GAIN_1_6&amp;quot;;
        zephyr,reference = &amp;quot;ADC_REF_INTERNAL&amp;quot;;
        zephyr,acquisition-time = &amp;lt;ADC_ACQ_TIME_DEFAULT&amp;gt;;
        zephyr,resolution = &amp;lt;12&amp;gt;;
    };
    

    channel@2 {
        reg = &amp;lt;2&amp;gt;;
        zephyr,input-positive = &amp;lt;NRF_SAADC_AIN2&amp;gt;; // Alternative syntax
        zephyr,gain = &amp;quot;ADC_GAIN_1_6&amp;quot;;
        zephyr,reference = &amp;quot;ADC_REF_INTERNAL&amp;quot;;
        zephyr,acquisition-time = &amp;lt;ADC_ACQ_TIME_DEFAULT&amp;gt;;
        zephyr,resolution = &amp;lt;12&amp;gt;;
    };
};&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I would send out the readings for charged and charging and&amp;nbsp;adc_raw_to_millivolts_dt I would get the following readings. The first one is&amp;nbsp;charging_val and the second is charged_val.&lt;/p&gt;
&lt;p&gt;When connected to power the readings would be:&lt;br /&gt;&lt;br /&gt;14,2284&lt;br /&gt;10,2293&lt;br /&gt;9,2284&lt;/p&gt;
&lt;p&gt;When not connected:&lt;/p&gt;
&lt;p&gt;0,2&lt;br /&gt;0,0&lt;br /&gt;0,0&lt;br /&gt;0,0&lt;br /&gt;0,0&lt;br /&gt;0,5&lt;br /&gt;7,0&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is it best to do these another way? I was going to try GPIO but seem to be having problems getting it to work. I tried testing by commenting out the channel 1 &amp;amp; 2 and putting this in the overlay:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;gpio0 {
    status = &amp;quot;okay&amp;quot;;

    chargerstatus: charger_status {
        compatible = &amp;quot;gpio-battery-charger-status&amp;quot;; // Add this line
        gpio-hog;
        gpios = &amp;lt;6 GPIO_ACTIVE_LOW&amp;gt;;
    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;but getting device is not ready when doing:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CHARGER_STATUS_NODE DT_NODELABEL(chargerstatus)
static const struct gpio_dt_spec charger_gpio = GPIO_DT_SPEC_GET_OR(CHARGER_STATUS_NODE, gpios, {0});
static bool charger_gpio_initialized = false;	
	
	
	
int test_init() {
	
	if (!gpio_is_ready_dt(&amp;amp;charger_gpio)) {
		LOG_ERR(&amp;quot;Error: charger GPIO device is not ready&amp;quot;);
		return -1;
	} else {
		LOG_DBG(&amp;quot;Charger GPIO device is ready&amp;quot;);
	}

	int ret = gpio_pin_configure_dt(&amp;amp;charger_gpio, GPIO_INPUT);
	if (ret != 0) {
		LOG_ERR(&amp;quot;Error %d: failed to configure charger GPIO pin&amp;quot;, ret);
		return -1;
	} else {
		LOG_DBG(&amp;quot;Charger GPIO pin configured successfully&amp;quot;);
	}
	
	return 0;
	
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I tried using this:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CHARGING_STATUS_NODE DT_NODELABEL(charging_status)
static const struct gpio_dt_spec charger_gpio = GPIO_DT_SPEC_GET(CHARGING_STATUS_NODE, gpios);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But am geting the same sort of error this person is getting in the post &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/101607/gpio-pin-configuration-using-devicetree"&gt;GPIO pin configuration using Devicetree&lt;/a&gt;. I would think there is a common configuration for P0.05 and P0.06 on a nrf5340.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Determining charged and charging on custom board with nrf5340</title><link>https://devzone.nordicsemi.com/thread/542383?ContentTypeID=1</link><pubDate>Mon, 14 Jul 2025 12:20:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e96ab67-1e96-45d0-8630-b882f9564218</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Your application can measure the battery voltage on P0.04 using the SAADC exactly as in the Zephyr battery sample. Your external divider scales the pack voltage down into the ADC range; after sampling, we multiply by 7.666 to recover the real battery voltage in millivolts.&lt;/p&gt;
&lt;p&gt;For charging status your application can tread the charger IC’s two pins, CHG and STAT as digital signals rather than analog inputs.The CHG pin lights up whenever your charger is actually pumping current into the battery. The STAT pin becomes on once the battery is full or the charger has gone idle. You just need to connect CHG to P0.05 and STAT to P0.06 on the nRF5340, add a pull-up to 3.3 V and set them up as normal digital inputs.&lt;/p&gt;
&lt;p&gt;In firmware, every sampling loop (e.g. once per 5 s):&lt;/p&gt;
&lt;p&gt;Read the SAADC channel on P0.04, convert the raw sample to millivolts (applying the divider ratio), and report “Battery: X mV.” &lt;br /&gt;Read P0.05 and P0.06 as digital inputs:&lt;/p&gt;
&lt;p&gt;If CHG is asserted, print “Charger: CHARGING.” Else if STAT is asserted, print “Charger: FULL/STANDBY.” Otherwise, print “Charger: NO POWER.”&lt;/p&gt;
&lt;p&gt;This way you keep your SAADC pipeline focused on the analog battery voltage. &lt;br /&gt;Use straightforward HIGH/LOW GPIO reads (and interrupts, if you like) for charger events. &lt;br /&gt;Avoid extra dividers or calibration on the CHG/STAT lines, since they’re inherently digital.&lt;br /&gt;You’ll need only minimal Zephyr DT overlays (to bind the two GPIOs) and standard gpio_pin_get() calls alongside your existing ADC setup.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>