<?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>Best pratice to detect pin changes with high reliability?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17157/best-pratice-to-detect-pin-changes-with-high-reliability</link><description>Hello there. 
 I&amp;#180;m using a Taiyo Yuden evaluation board with a nRF51422 to connect with 3 different sensors. In addition to that there are also 2 buttons connected to the eval board. The collected data get&amp;#180;s sent over UART. I used the app_uart_c example</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Oct 2016 15:06:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17157/best-pratice-to-detect-pin-changes-with-high-reliability" /><item><title>RE: Best pratice to detect pin changes with high reliability?</title><link>https://devzone.nordicsemi.com/thread/65911?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2016 15:06:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8659d164-03d2-4b4f-96ec-f928a89ff5c3</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;You receive events on falling edge when you configure LOTOHI?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;First, how can i set up two events (one for LOTOHI and HITOLO) for one pin&lt;/em&gt; This is discussed &lt;a href="https://devzone.nordicsemi.com/question/66905/using-two-gpiote-config-to-a-single-pin/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;how do i get the pin value on TOGGLE&lt;/em&gt; I don&amp;#39;t know of any way that guarantees that the pin value is correct, when the the interrupt is not handled instantly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best pratice to detect pin changes with high reliability?</title><link>https://devzone.nordicsemi.com/thread/65910?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2016 12:33:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:175d0bb9-d073-4fd6-a82b-257fcddbeff5</guid><dc:creator>Vehring</dc:creator><description>&lt;p&gt;Ok thanks for your help.&lt;/p&gt;
&lt;p&gt;The APP_IRQ_PRIORITY doesn´t solve the problem but the IN events do.
But now i face new issues with the pin value.&lt;/p&gt;
&lt;p&gt;I stick to the code of the pin_change_int example. When the pin is configered to TOGGLE i don´t know the value and just toggling my bit is not a solution. Reading the pin value in the event handler with nrf_drv_gpiote_in_is_set returns me sometimes the wrong state or doesn´t seem to be accurate
However also if i only configure it to detect rising edges i get events on the falling edge.&lt;/p&gt;
&lt;p&gt;So how to handle this?
First, how can i set up two events (one for LOTOHI and HITOLO) for one pin or how do i get the pin value on TOGGLE?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)

	switch (pin)
	
		case BSP_BUTTON_0:
			button_0 = nrf_drv_gpiote_in_is_set(BSP_BUTTON_0);		
			break;
		case BSP_BUTTON_1:
			button_1 = nrf_drv_gpiote_in_is_set(BSP_BUTTON_1);
			break;
	
	button_update = true;

static void gpio_init(void)

ret_code_t err_code;

err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;

err_code = nrf_drv_gpiote_in_init(BSP_BUTTON_0, &amp;amp;in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);

	err_code = nrf_drv_gpiote_in_init(BSP_BUTTON_1, &amp;amp;in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_event_enable(BSP_BUTTON_0, true);
	nrf_drv_gpiote_in_event_enable(BSP_BUTTON_1, true);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;P.S.: I left out the brackets because they corrupt the highlighting of the code&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best pratice to detect pin changes with high reliability?</title><link>https://devzone.nordicsemi.com/thread/65909?ContentTypeID=1</link><pubDate>Fri, 21 Oct 2016 12:01:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b731289-cd0f-43a6-9234-b2955d1a8376</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;I don&amp;#39;t think calling ble_stack_init before APP_TIMER_INIT matters.&lt;/p&gt;
&lt;p&gt;The app button library uses the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.0.0/hardware_driver_gpiote.html?cp=4_0_0_2_5"&gt;GPIOTE driver&lt;/a&gt; in
low accuracy/low power mode. In this mode the PORT event/interrupt is used to sense level changes on the pin. With the app button library the PORT event is triggered every time a pin toggles. It is not very accurate, and cannot be used to track high speed pin changes.&lt;/p&gt;
&lt;p&gt;When you get the PORT event you do not know which pin that generated the event (unless you only have activated one pin), which means that you have to read the state of pins when you get this event. This means that if the PORT event is not handled quickly enough the state of the pins might actually have changed again.&lt;/p&gt;
&lt;p&gt;Until the event is handled the event can&amp;#39;t be triggered again, and all changes will be lost.&lt;/p&gt;
&lt;p&gt;I see in your project that the priority of the GPIOTE interrupt (GPIOTE_CONFIG_IRQ_PRIORITY) is set to 3 (APP_IRQ_PRIORITY_LOW). This means that any interrupts with higher priority will be handled first, which means that you potentially lose more changes. You can try to change it to APP_IRQ_PRIORITY_HIGH, see if that helps, but you will not be able to high priority &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s130.sds/dita/softdevices/s130/processor_avail_interrupt_latency/exception_mgmt_sd.html?cp=3_6_2_0_15_1"&gt;SoftDevice interrupts&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If not, I think you need to look into using the IN events instead of the PORT event. If you have two buttons you can tie these to two IN events. Then you will at least know what pin that triggered the event.&lt;/p&gt;
&lt;p&gt;You are still vulnerable to losing changes on the same pin if the IN event for that pin is not handled quickly enough. Then I think you need to do something like what is discussed &lt;a href="https://devzone.nordicsemi.com/question/66905/using-two-gpiote-config-to-a-single-pin/"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best pratice to detect pin changes with high reliability?</title><link>https://devzone.nordicsemi.com/thread/65908?ContentTypeID=1</link><pubDate>Thu, 20 Oct 2016 12:00:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0cef61b-4cc2-4c3c-9f81-e2fa57bae1a3</guid><dc:creator>Vehring</dc:creator><description>&lt;p&gt;My basic project is the ble_app_c example and modified it. I use the arm5_no_packs from the pca10028 board project.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://dl.dropboxusercontent.com/u/87950656/161020_ble_app_uart_c.7z"&gt;Dropbox Project Link&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don´t know if the call of ble_stack_init before the APP_TIMER_INIT hat any effect because i found out that the buttons were slightly damaged during soldering. However with new buttons the problem still exists and i must not miss a falling edge when i received a rising edge.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best pratice to detect pin changes with high reliability?</title><link>https://devzone.nordicsemi.com/thread/65907?ContentTypeID=1</link><pubDate>Thu, 20 Oct 2016 10:16:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:440c1356-7649-4407-ae9f-890741bc4456</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Could you share your project so I can have a look? Or a project where this is reproducible?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>