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

Event vs Interrupt

Hi All,

I am developing a data acquisition system in which my device generates an interrupt for every 5ms upon its data is ready. I store one second long data in local buffer and write it into external flash memory every 1 second. 

I am bit confused with GPIO events and interrupts in nRF. I guess any level change on a input pin is called an event in nRF. If that is true I would like to configure one GPIO as input and configure an event (High to Low in my case) then assign it to an event handler. 

And then, I have read below lines in SDK documentation, 

When a SoftDevice is enabled, it can interrupt the application at any time for a certain amount of time. This can lead to the situation where some pin level changes are missed. If the application must track an input pin that can change its level frequently, PPI should be used with a high-accuracy event together with a TIMER in counter mode to count the detected transitions.

Below are my queries:

  1. My interrupt is generated every  5ms infinitely, and I cannot afford any single interrupt to lose. I would like to know how can I configure my interrupt handling mechanism to avoid data loss? 
  2. If I use PPI with Timer to count the interrupts I have missed from my peripheral, how can I retrieve data from my device at later point? 
  3. What is a softdevice? how it can interrupt the application? 
  4. I need some help understanding event. Previously i was using a processor where any GPIO can be configured for external interrupts which is very straight forward. In nRF it seems there is no interrupt concept for GPIO rather they call it as event. 

Any help would be highly appreciated. 

Regards

Laskhmi

  • Hi Laskhmi,

    My interrupt is generated every  5ms infinitely, and I cannot afford any single interrupt to lose. I would like to know how can I configure my interrupt handling mechanism to avoid data loss? 

    5 ms is quite a long time, so it should not be a problem to ensure that you never miss any of these interrupts. However, it might be that the interrupt processing is delayed a bit, but that may not be a problem? You can refer to the Interrupt model and processor availability in the SoftDevice documentation to see the maximum time the SoftDevice will delay the application, and as you see that is in any case significantly less, giving you a lot of margin.

    If I use PPI with Timer to count the interrupts I have missed from my peripheral, how can I retrieve data from my device at later point? 

    That depends on the peripheral. But I do not see this a likely problem since the frequency of the interrupt is so slow. 

    What is a softdevice? how it can interrupt the application? 

    A SoftDevice is Nordic's proprietary BLE stack. It needs to have the highest interrupt priority since Bluetooth has strict timing requirements, and several low-level radio interrupts need to be serviced in a timely manner.

    I need some help understanding event. Previously i was using a processor where any GPIO can be configured for external interrupts which is very straight forward. In nRF it seems there is no interrupt concept for GPIO rather they call it as event. 

    You can think of interrupts and events in the same way. When the application gets a. SoftDevice event, it is actually a software interrupt. And when there is a pin change interrupt form a GPIO, the SDK driver you typically use will have it's interrupted routine run, and this will call the applications event handler in the interrupt context. So it is in practice the same. (If you look at the terms used in the ARM documentation, you will also see interrupts and events used. In this case, it is also essentially the same, but some minimal differences. In the nRF peripheral HW context, the difference is bigger, since you can have HW events that trigger interrupts or not, depending on the configuration. But that is probably not relevant for your question in this case.)

  • Hi Einar Thorsrud, 

    Thanks for the information. It was very useful to get started. 

    Currently  I am using heartrate application. I have below queries. 

    In this application,  ble_hrs_heart_rate_measurement_send(&m_hrs, heart_rate)  is used to send the measurement to the central. But it seems it is sending only two byte value (which is heart_rate parameter in this case)when each time it gets called. 

    But my application needs to send more data for each time the heartrate_timer expires. 

    Assuming default ATT_MTU 23 bytes has been set in this example, how to send a 20bytes packet in one shot?

    Is there any internal FIFO available in BLE stack to fill the data to be continuously sent in 20bytes chunks or more by setting ATT_MTU to its max value? Because I have to send real time data continuously. But I am not sure how to use ble_hrs_heart_rate_measurement_send API to achieve this. 

    Please help me. 

    Regards

    Lakshmi

  • Hi Lakshmi,

    Lakshmikanth Satyavolu said:
    Assuming default ATT_MTU 23 bytes has been set in this example, how to send a 20bytes packet in one shot?

    In that case, you would need to send all this data in one notification. This is because even though an ATT packet can span multiple link layer (LL) packets, there cannot be multiple ATT packets in a single LL packet. But if you do that, your device will not comply with the Heart Rate Profile. So I suspect a better solution is to send several notifications and use a configuration that allows multiple packets per connection event if you really need to get the data simultaneously. It will give you a bit more overhead (unless interoperability is irrelevant for your application).

    Lakshmikanth Satyavolu said:
    Is there any internal FIFO available in BLE stack to fill the data to be continuously sent in 20bytes chunks or more by setting ATT_MTU to its max value? Because I have to send real time data continuously. But I am not sure how to use ble_hrs_heart_rate_measurement_send API to achieve this. 

    There is a FIFO of LL packets, so if you fill it with several packets, it will be sent in one connection interval if there is time (and there are no retransmissions).

    Einar

  • Hi Einar Thorsrud

    Can you suggest an example application if any, or API to be used for to write into FIFO please? 

    Regards

    Lakshmi

  • Hi Lakshmi,

    Lakshmikanth Satyavolu said:
    Can you suggest an example application if any, or API to be used for to write into FIFO please? 

    Assuming we are talking about notifications here, just send more notifications, and they will be put in a FIFO in the SoftDevice. This is not something you need to think of, other than handling a full FIFO, where you get NRF_ERROR_RESOURCES returned from the call to sd_ble_gatts_hvx().

    If this does not answer your question, then please elaborate exactly what you want (remembering that there is no more than one ATT packet in a single LL packet, as mentioned before).

    Einar

Related