This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

spi_event_handler can not be triggered after button is pushed.

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 triggered(in function bsp_event_handler), the function getT() does not work correclty.

Trace the codes, I find the function spi_event_handler() does not be called and causes err_code = NRF_ERROR_BUSY in function nrf_drv_spi_xfer.

I.E. the funtion spi_event_handler() will not be called after the funtion bsp_event_handler() is called.

The following is part of my codes:

int main(void)
{ ....
  spi_config();
  getT();
  ....
}

In above code, the function getT() in the main() block is work correctly.

static void bsp_event_handler(bsp_event_t event)
{ .....
  switch (event) {
     ....
     case BSP_EVENT_KEY_4:
     getT();
  }
  ....
}

In above code, the function getT() can not work correctly when it is put in the bsp_event_handler block.(The spi_event_handler does not be called)

How can I fixed this issue?

Thank you for your help. Best Wishes

  • The fact that getT() works in main, but not when you call it from within a handler (interrupt) points to a problem with interrupt priorities or nesting?

  • hi! Thank you for your reply The following is part of my codes:

       int main(void)
        { ....
          spi_config();
          getT();
          ....
        }
    

    In above code, the function getT() in the main() block is work correctly.

    static void bsp_event_handler(bsp_event_t event)
    { .....
      switch (event) {
         ....
         case BSP_EVENT_KEY_4:
         getT();
      }
      ....
    }
    

    In above code, the function getT() can not work correctly when it is put in the bsp_event_handler block.(The spi_event_handler does not be called)

  • 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.

    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.

    Your description of your issue seems to suggest something like that.

    Can you post the source for getT()?

    If you can'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.

  • In fact, in re-reading your description, I think the comments from Martin and I may be your issue.

    I'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().

    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.

    When you call getT() from main() your device is not in an event handling state. In this case the SPI events can be handled.

    The two links in Martin's reply describe this type of issue.

    Martin'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.

    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.

  • 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.
    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 !

Related