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

Best pratice to detect pin changes with high reliability?

Hello there.

I´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´s sent over UART. I used the app_uart_c example to implement my code.

Now i have problems to recognize every button press. This seems to me related to the softdevice. I modified the bsp code which works so far but sometimes i only manage to execute the event handler every second press. Searching for any issues i decided to first initialize the ble stack to start the lf clk and after initialize the timer which in my feeling was an improvement in the response. However the result is not satisfying for me. I rather don´t want to miss any button press. Is there a solution that can handle pin change interrupts and softdevice reliable at the same time?

Parents
  • I don't think calling ble_stack_init before APP_TIMER_INIT matters.

    The app button library uses the GPIOTE driver 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.

    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.

    Until the event is handled the event can't be triggered again, and all changes will be lost.

    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 SoftDevice interrupts.

    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.

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

  • You receive events on falling edge when you configure LOTOHI?

    First, how can i set up two events (one for LOTOHI and HITOLO) for one pin This is discussed here.

    how do i get the pin value on TOGGLE I don't know of any way that guarantees that the pin value is correct, when the the interrupt is not handled instantly.

Reply Children
No Data
Related