Closed
Description
I'm experiencing problems with multiple tickers in the nRF51822, actually it's something similar to what is described in #832.
I have reproduced the error with a mod of the Nordic UART example. I've added to the sample code three tickers:
- Each 20 ms to increase a counter
- Each 10 ms to increase another counter
- Each second to send the counters values through the BLE UART
After some seconds I stop receiving data and sometimes the connection is lost after a while but most of the times it is not lost, so I can disconnect and the firmware will respond properly. I've also detected with a different code that after this hang, if I wait long enough, the tickers start working again.
I have the libraries updated so this problem should be solved. Is anyone else having it?
#include <string.h>
#include "mbed.h"
#include "BLE.h"
#include "UARTService.h"
#define NEED_CONSOLE_OUTPUT 1 /* Set this if you need debug messages on the console;
* it will have an impact on code-size and power consumption. */
#if NEED_CONSOLE_OUTPUT
#define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); }
#else
#define DEBUG(...) /* nothing */
#endif /* #if NEED_CONSOLE_OUTPUT */
BLEDevice ble;
DigitalOut led1(LED1);
UARTService *uart;
bool cb3 = false;
int cb1_counter, cb2_counter;
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
DEBUG("Disconnected!\n\r");
DEBUG("Restarting the advertising process\n\r");
ble.startAdvertising();
}
void periodicCallback1(void)
{
cb1_counter++;
}
void periodicCallback2(void)
{
cb2_counter++;
}
void periodicCallback3(void)
{
cb3 = true;
}
void maintask() {
if(cb3) {
cb3 = false;
char str1[15];
sprintf(str1, "CB1 %i\r\n", cb1_counter);
DEBUG(str1);
char str2[15];
sprintf(str2, "CB2 %i\r\n", cb2_counter);
DEBUG(str2);
}
}
int main(void)
{
led1 = 1;
Ticker ticker1, ticker2, ticker3;
ticker1.attach_us(periodicCallback1, 20000);
ticker2.attach_us(periodicCallback2, 10000);
ticker3.attach_us(periodicCallback3, 1000000);
DEBUG("Initialising the nRF51822\n\r");
ble.init();
ble.onDisconnection(disconnectionCallback);
uart = new UARTService(ble);
/* setup advertising */
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
(const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
(const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
ble.startAdvertising();
while (true) {
ble.waitForEvent();
maintask();
}
}