Hi,
I would like to make some measurements via I2C in radio_notification_evt_handler. Unfortunately, after executing a random number of measurements, the advertising stops, as well as the measurements. I suspect that the reason for this could be a too long execution time of same calling of my radio notification handler (I'm using the NRF_RADIO_NOTIFICATION_DISTANCE_5500US and the irq priority is 3). I tried to resolve this problem by starting hfclk like in that code:
void radio_notification_evt_handler(bool radio_evt)
{
if (radio_evt)
{
uint32_t p_is_running=0;
sd_clock_hfclk_request();
while (!p_is_running) {sd_clock_hfclk_is_running(&p_is_running);}
LEDS_OFF(BSP_LED_3_MASK);
if((z%2)==0)i2c_temp();
if((z%2)==1)i2c_humidity();
history_temperature[z/2]=current_temperature;
history_humidity[z/2]=current_humidity;
if(z<50) z++;
else z=0;
LEDS_ON(BSP_LED_3_MASK);
sd_clock_hfclk_release();
}
else
{
//radio inactive
}
}
Despite starting the HF clock, the time of execution of measurements didn't change (I see the time of execution by the time that the LED3 is OFF). The same code with I2C while being executed during connection with another BLE device (in timer_timeout_handler written like in devzone.nordicsemi.com/.../ ) is executing much more faster.
The next step that I tried was using the Timer1 in order to stop the measurements that were taking too long (implementation of the Timer1 is pattern on timer example from SDK). Firstly, I tried to check the repeatability of the timer_led_event_handler calls duration, like in that code below.
The timer_led_event_handler is supposed to turn on the next LEDs while its execution. The duration of the timer counting should be 100 ms (time_ms) but it's stretch from short blinks to almost 1.5 second periods (without service of i2c protocol this time, as in code below). This executing times are almost the same like previously.
#include "nrf_drv_timer.h"
//some code
#define APP_ADV_INTERVAL 8500
//some code
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;
uint32_t time_ms = 100; //Time(in miliseconds) between consecutive compare events.
uint32_t time_ticks;
uint8_t timer_flag=0;
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
static uint32_t i;
uint32_t led_to_invert = (1 << leds_list[(i++) % LEDS_NUMBER]);
nrf_drv_timer_disable(&TIMER_LED);
switch(event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
LEDS_INVERT(led_to_invert);
timer_flag=1;
break;
default:
//Do nothing.
break;
}
}
//some code
void radio_notification_evt_handler(bool radio_evt)
{
if (radio_evt)
{
//radio going active
uint32_t p_is_running=0;
sd_clock_hfclk_request();
while (!p_is_running) {sd_clock_hfclk_is_running(&p_is_running);}
nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_LED);
if(timer_flag){sd_clock_hfclk_release(); timer_flag=0;}
}
else
{
//radio inactive
}
//some code
int main(void)
{
//some code
err_code = NRF_SUCCESS;
//Configure all leds on board.
LEDS_CONFIGURE(LEDS_MASK);
LEDS_OFF(LEDS_MASK);
//Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
err_code = nrf_drv_timer_init(&TIMER_LED, NULL, timer_led_event_handler);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
// Enter main loop.
for (;;)
{
power_manage();
}
return 0;
}
The setup of the timer (62-65 lines in nrf_drv_config.h) that I tried was the default one or with high irq priority. The advertising interval is set to 8500.
Besides that, when I used the radio notification handler with timer (and without communication via I2C), the executing took similar time as the radio notification handler with I2C communication. However, in that case I didn't have any problem with the stopping of advertising.
Any help would be appreciated.
I'm using S130 softdevice and SDK 11.0.0.