<?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>spi_event_handler can not be triggered after button is pushed.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/25918/spi_event_handler-can-not-be-triggered-after-button-is-pushed</link><description>hi 
 I write a function getT() to read spi thermalcouple chip.
if the function getT() is called in main() function, it will work correctly. Hence, I think that getT() is correct essentially. 
 if the function getT() is called when BSP_EVENT_KEY4 is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Oct 2017 14:28:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/25918/spi_event_handler-can-not-be-triggered-after-button-is-pushed" /><item><title>RE: spi_event_handler can not be triggered after button is pushed.</title><link>https://devzone.nordicsemi.com/thread/102092?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2017 14:28:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5f76746-6975-4eff-9b7b-f48a70958661</guid><dc:creator>kaochin</dc:creator><description>&lt;p&gt;Thank everyone who replies and comments.
But it seems difficult to solve in a short time, I think that I need spend times to study it.&lt;br /&gt;
I adopt another way to accomplish the purpose of the program.
Your comments are very helpful to clarify my issue, they are worth to study.
Thank you very much !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi_event_handler can not be triggered after button is pushed.</title><link>https://devzone.nordicsemi.com/thread/102091?ContentTypeID=1</link><pubDate>Sat, 14 Oct 2017 09:23:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c774675f-e15c-454a-a6bc-68ccd615b3c8</guid><dc:creator>ta2</dc:creator><description>&lt;p&gt;In fact, in re-reading your description, I think the comments from Martin and I may be your issue.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m going to make a guess that getT() is issuing SPI commands. The SPI commands complete asynchronously which is why you need an spi_event_handler().&lt;/p&gt;
&lt;p&gt;When you try to use getT() from bsp_event_handler(), your device is in an event handlng state. While in that state, it is very likely that NO other events (like events coming from SPI) can be processed.&lt;/p&gt;
&lt;p&gt;When you call getT() from main() your device is not in an event handling state. In this case the SPI events can be handled.&lt;/p&gt;
&lt;p&gt;The two links in Martin&amp;#39;s reply describe this type of issue.&lt;/p&gt;
&lt;p&gt;Martin&amp;#39;s links refer to nested interrupts, but many event handlers are actually invoked from interrupt handlers. Your button press generates an interrupt which is passed to the event handler.&lt;/p&gt;
&lt;p&gt;At that point your device may be in both interrupt and event handling states, which likely will block the interrupts and/or events coming from SPI.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi_event_handler can not be triggered after button is pushed.</title><link>https://devzone.nordicsemi.com/thread/102090?ContentTypeID=1</link><pubDate>Sat, 14 Oct 2017 08:56:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78f3ded1-fee4-4165-8fba-e11667234b60</guid><dc:creator>ta2</dc:creator><description>&lt;p&gt;The interrupt and event handling states/levels are commonly not re-entrant, or may not allow a given interrupt or event to be processed from an interrupt or event handler.&lt;/p&gt;
&lt;p&gt;For example, if getT() is doing something that causes an event to be triggered, it may not be possible to handle the (getT()) generated event from an event handler.&lt;/p&gt;
&lt;p&gt;Your description of your issue seems to suggest something like that.&lt;/p&gt;
&lt;p&gt;Can you post the source for getT()?&lt;/p&gt;
&lt;p&gt;If you can&amp;#39;t post the source for getT() here in the forum because of confidentiality, you can open a service ticket. Information provided in service tickets is only seen by Nordic employees and is protected from disclosure to any customer other than your company.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi_event_handler can not be triggered after button is pushed.</title><link>https://devzone.nordicsemi.com/thread/102089?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 13:26:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37e6cd90-d30e-4fe8-9252-71e20a22efc2</guid><dc:creator>kaochin</dc:creator><description>&lt;p&gt;hi!
Thank you for your reply
The following is part of my codes:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;   int main(void)
    { ....
      spi_config();
      getT();
      ....
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In above code, the function &lt;code&gt;getT()&lt;/code&gt; in the main() block is work correctly.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void bsp_event_handler(bsp_event_t event)
{ .....
  switch (event) {
     ....
     case BSP_EVENT_KEY_4:
     getT();
  }
  ....
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In above code, the function &lt;code&gt;getT()&lt;/code&gt; can not work correctly when it is put in the  &lt;code&gt;bsp_event_handler&lt;/code&gt; block.(The &lt;code&gt;spi_event_handler&lt;/code&gt; does not be called)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: spi_event_handler can not be triggered after button is pushed.</title><link>https://devzone.nordicsemi.com/thread/102088?ContentTypeID=1</link><pubDate>Fri, 13 Oct 2017 11:15:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe7ddf51-b76c-4b40-b7a4-31ad964402eb</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;The fact that getT() works in main, but not when you call it from within a handler (interrupt) points to a problem with interrupt &lt;a href="https://devzone.nordicsemi.com/question/79226/can-ble_nus_string_send-be-called-from-a-twi-callback/"&gt;priorities&lt;/a&gt; or &lt;a href="https://devzone.nordicsemi.com/question/68758/twi-function-not-working-when-called-from-a-pin-interrupt-handler/"&gt;nesting&lt;/a&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>