7 years, 2 months ago.

BLE::waitForEvent()

Hello.

I'm using mbed board Ty51822r3 with nRF51822. In this environment, BLE::waitforEvent is transported to nRF5xn::waitForEvent().

nRF5xn.cpp

void nRF5xn::waitForEvent(void)
{
    processEvents();
    sd_app_evt_wait();
}

I developed my BLE peripheral application with BLE API. Busy-loop in main method like below.

my code

while (true)
{
	ProcessMyEvent();
	ble.waitForEvent();
}

This code does not work well. ble.waitForEvent() call processEvents(), and BLE callbacks enqueue my events.

But after that, Call sd_app_evt_wait() and go into sleep. Therefore, I can not process my events.

I exchange the order of processEvent() & sd_app_evt_wait() in ble.waitForEvent() for this problem. It seems well. Is there any problem for this solution?

Question relating to:

Bluetooth Low Energy (a.k.a Bluetooth LE, BTLE, Bluetooth Smart)

1 Answer

7 years, 1 month ago.

waitForEvent() puts the processor to sleep until a hardware interrupt occurs. Try setting up a ticker to wake up the processor periodically.

    ...
    Ticker ticker;
    ticker.attach(wakeup_event_cb, 0.1);
    while (true) {
        ProcessMyEvent();
        ble.waitForEvent();
    }
    ...

The callback doesn't have to do anything, just be there.

void wakeup_event_cb() {
    //nothing to do
};

Accepted Answer