<?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>NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37472/nrf52-interrupt-logic-level-event-handler</link><description>Hello, 
 I am doing a project on a NRF52DK, using SDK15 and SES. 
 I have been trying to implement a basic feature, which will be a part of a bigger system: 
 
 Detect interrupt from sensor (HIGH or LOW) 
 When HIGH:
 
 //do something 
 
 
 When LOW
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 17 Aug 2018 17:53:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37472/nrf52-interrupt-logic-level-event-handler" /><item><title>RE: NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/thread/144770?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 17:53:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8303d27-67a1-4dc1-b74c-fb0f523c20ac</guid><dc:creator>devops</dc:creator><description>&lt;p&gt;Thank you for such a constructive and towards solution leading reply. I will follow your instructions!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/thread/144663?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 09:19:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:751dafb8-9836-48de-ae7e-2c09fec09599</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The BSP library (without modifications) looks like it is only meant for simple button handling. To be honest, it is a bit confusing, and difficult to understand how it works.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to use a button library, I suggest that you use the app_button.c/h directly library instead. This is also used by the bsp library, but the bsp library strips away an awful lot in the actual event. You will only get the button number in the bsp event, and you can&amp;#39;t trigger the event on both push and pull.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Look into the app_button instead.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The app_button library is good if you intend to use it for physical buttons, because it has a debounce filter functionality. If you intend to control the GPIOs by wires (and don&amp;#39;t need debounce), I don&amp;#39;t see a reason why not to use the pin_int_change implementation.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/thread/144526?ContentTypeID=1</link><pubDate>Thu, 16 Aug 2018 12:16:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:927387b6-a81c-42cd-b79f-375f2d52d502</guid><dc:creator>devops</dc:creator><description>&lt;p&gt;Thank you for replying. I do not want to have the&amp;nbsp;&lt;em&gt;flush&amp;nbsp;&lt;/em&gt;in the handler. This was just for testing and due to my lack of knowledge I tried out many things which were not working. I wanted to add the logging feature to the application in Segger Studio but did not get it to work even though I added the header files in main.c and CMSIS had the necessary defines enabled.&lt;/p&gt;
&lt;p&gt;Right now I have moved a bit on from the initial problem as I was not able to do my function how I want, which is an event handler in&amp;nbsp;&lt;em&gt;bsp_event_handler&amp;nbsp;&lt;/em&gt;and where I could sense if the pin has went from high to low or vice versa. I am using right now the&amp;nbsp;&lt;em&gt;pin_int_change&amp;nbsp;&lt;/em&gt;which obviously works but my goal is to get the same function to work in bsp. I feel that I need to learn a bit more pointers, callbacks and events - I was trying to trace down how the&amp;nbsp;&lt;em&gt;bsp_event_handler&amp;nbsp;&lt;/em&gt;gets called and how to assign events to custom pins on the board but got confused in the process... If you have any thoughts, feel free to share them and I will try them out.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/thread/144466?ContentTypeID=1</link><pubDate>Thu, 16 Aug 2018 09:17:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d820416a-cc52-463a-b08f-1ebf22311303</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I suspect that you have some IRQ priority issues, when you move the flush function to your event handler. It is trying to run the event handler, but is not allowed, since the event has a higher priority, so you are stuck in a deadlock. You can try to lower your interrupt priority, but is there a reason for why you need to move the flushing to the event handler? You can still call NRF_LOG_INFO(); from your events.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/thread/144250?ContentTypeID=1</link><pubDate>Wed, 15 Aug 2018 06:08:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74045f51-1a7e-4e1d-a943-01ca6561e2d0</guid><dc:creator>devops</dc:creator><description>&lt;p&gt;Good morning. Thank you for your answer. Something like that is the easiest approach indeed and I had an example working like that.&lt;/p&gt;
&lt;p&gt;What I would like is:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;&lt;pre class="ui-code" data-mode="text"&gt;void event handler(event){

    switch(event){
    
        case interrupt_high: //**// break;
        
        case interrupt_low: //**// break;
        
        case reset_button_toggle: //**// break;
        
        case another_button_long_press: //**// break;
        
        default: break;

}}&lt;/pre&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I think that this would be a better approach for multiple events that may happen further along as the system evolves and new peripherals are added and the clear example is &lt;em&gt;bsp_event_handler(bsp_event_t event).&amp;nbsp;&lt;/em&gt;I will start experimenting again and appreciate any instructions.&lt;/p&gt;
&lt;p&gt;EDIT: Have not got anything to work... I tried to make a event handler again but without luck. Now I tried again with the simpler example and having problems as well. When I log the text to console, while having&amp;nbsp;&lt;em&gt;NRF_LOG_FLUSH&amp;nbsp;&lt;/em&gt;in the while loop in main, then it works. If I flush logs inside the handler, then the handler ceases to work (doesnt detect pin changes anymore). If I want to get the temperature from SPI and print it inside the handler, it does not print anything and ceases to function.&lt;/p&gt;
&lt;p&gt;This seems really complicated to implement... does anybody have some good suggestions?&lt;/p&gt;
&lt;p&gt;I would like to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Detect interrupts from sensor (active/inactive)&lt;/li&gt;
&lt;li&gt;Then based on that, set the state of the machine (machine is working, not working etc.)&lt;/li&gt;
&lt;li&gt;If the machine would be working, then get data from sensor with SPI and update advertising package with the data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I have a separate file where the SPI connection works and in another file where I can send test BLE data in manufacturer data. I want to have a low-power communication where I just send sensor data through BLE to phone when machine is working and I am trying to implement features step by step - in the hopes of combining smaller functions in the end.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    if(nrf_gpio_pin_read(INT_2) == 0){
        NRF_LOG_INFO(&amp;quot;Machine active&amp;quot;);
        //float temperature = read_temperature();
        //NRF_LOG_INFO(&amp;quot;Temperature is: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot;\r\n&amp;quot;, NRF_LOG_FLOAT(temperature));
        //NRF_LOG_FLUSH();
    }
    else if(nrf_gpio_pin_read(INT_2) == 1){
        NRF_LOG_INFO(&amp;quot;Machine inactive&amp;quot;);
        //NRF_LOG_FLUSH();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 interrupt logic level event handler</title><link>https://devzone.nordicsemi.com/thread/144174?ContentTypeID=1</link><pubDate>Tue, 14 Aug 2018 12:43:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d7f4aa86-edd0-4ded-b59c-dbcb2f77a529</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;If I understand you correctly, you want an interrupt whenever a pin changes state, and you want to do an action depending on what state the pin is in.&lt;/p&gt;
&lt;p&gt;so something like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;pin_interrupt_callback()
{
    if (pin_is_pressed)
    {
        //do something
    }
    else if(pin_is_not_pressed)
    {
        //do something else
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is that correct?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A very simple approach is using the pin_int_change example, and adding something in the handler to read the state of the pin. You can e.g. use nrf_gpio_pin_read(uint32_t pin_number);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you take the SDK15\examples\peripheral\pin_int_change, and replace the main file with the attached main file, it should toggle one of the LEDs when you push the button down, and another when you release it.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-960e9dd4b19b4b598857b3c932c28008/main.c"&gt;devzone.nordicsemi.com/.../main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvinn&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>