<?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>Charging indication by LED glow</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/31289/charging-indication-by-led-glow</link><description>hello guys 
 i am trying to glow LED while my device gets charging. i have nrf52832 custom board and P0.17 connected to USB supply using voltage divider. when i plug in usb this pin 17 should be high and when i removed usb this pin sholud be low. but</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 09 Mar 2018 11:34:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/31289/charging-indication-by-led-glow" /><item><title>RE: Charging indication by LED glow</title><link>https://devzone.nordicsemi.com/thread/123641?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 11:34:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94190129-defa-4aac-9e8f-5df3b4f70903</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;yes, with pull down it is working fine thank you so much&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Charging indication by LED glow</title><link>https://devzone.nordicsemi.com/thread/123633?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 11:10:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d9cfb44-0ce6-4f37-90a7-4a5a88b9e072</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;ok i will try sir&lt;/p&gt;
&lt;p&gt;thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Charging indication by LED glow</title><link>https://devzone.nordicsemi.com/thread/123632?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 11:07:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:346b4f06-7979-4969-8d63-63564fdbdba3</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;try to&amp;nbsp;set&amp;nbsp;NRF_GPIO_PIN_PULLDOWN instead of UP.&lt;br /&gt;I reworked my code to give an example, how to do it without loop, so there is no guaranty it works for you out of the box. ;-)&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Charging indication by LED glow</title><link>https://devzone.nordicsemi.com/thread/123626?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 10:41:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c137f646-9f2a-4ca7-a3f7-3306cc079721</guid><dc:creator>Rahul</dc:creator><description>&lt;p&gt;thanks for reply. i tried this when i plug in USB, LED is glowing but after removing USB , LED is ON only.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Charging indication by LED glow</title><link>https://devzone.nordicsemi.com/thread/123581?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2018 09:21:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90b64fbc-eb5a-43b7-8181-95549ef58941</guid><dc:creator>Martin</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;waht you are trying to do is&lt;/p&gt;
&lt;p&gt;you need to define pin 17 as input and detect the state with e.g. nrf_gpio_pin_read.&lt;/p&gt;
&lt;p&gt;I would suggest&amp;nbsp;to&amp;nbsp;watch for the state change and not read, cfg and set in a loop.&lt;/p&gt;
&lt;p&gt;I implemented it like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void init_power_detect(){
	nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
	in_config.pull = NRF_GPIO_PIN_PULLUP;

	err_code = nrf_drv_gpiote_in_init(DEV_PIN_CHARGE, &amp;amp;in_config, pin_handler_charge);
	if(nrf_gpio_pin_read(DEV_PIN_CHARGE)){
		NRF_LOG_DEBUG(&amp;quot;CHARGE ON &amp;gt; SENSE POWER OFF\r\n&amp;quot;);
		nrf_gpio_cfg_sense_input(DEV_PIN_CHARGE, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
		nrf_gpio_pin_set(LED_CHARGE);
	} else {
		NRF_LOG_DEBUG(&amp;quot;CHARGE OFF &amp;gt; SENSE POWER ON\r\n&amp;quot;);
		nrf_gpio_cfg_sense_input(DEV_PIN_CHARGE, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_HIGH);
		nrf_gpio_pin_clear(LED_CHARGE);
	}
}

void pin_handler_charge(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){
	if(pin == DEV_PIN_CHARGE)
	{
		switch(action){
		case NRF_GPIOTE_POLARITY_TOGGLE:
			if(nrf_gpio_pin_read(DEV_PIN_CHARGE)){
			    // 1 = Charging
				nrf_gpio_pin_set(LED_CHARGE);
			} else {
			    // 0 = NOT Charging
				nrf_gpio_pin_clear(LED_CHARGE);
			}
			break;
		}
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>