Hi,
I need to use timer in one of my projects.
SDK: nCS 2.3.0
Hardware: nRF52833 DK (1.0.1, 2021.37)
I have built a firmware, based on the beacon example, adding shell , ADC sampling and writing some data to flash.
Now, I want to add timer to submit some work to work queue, to sample ADC periodically.
I used k_timer API before, it worked fine, as far as I can tell. But this time, when I set it up in my code, timer expiry function gets called multiple times (4 times in a row).
Here is a snippet of the code, which is used to set up the timer:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void adc_sampling_work_handler(struct k_work *work)
{
int16_t adc_mv;
adc_mv = get_adc_measurement();
if(adc_mv == m_adc_mv)
{
return; // Don't update
}
m_adc_mv = adc_mv;
cst_adv_data.adc1[0] = (((int16_t)m_adc_mv) >> 8) & 0xFF;
cst_adv_data.adc1[1] = ((int16_t)m_adc_mv) & 0xFF;
bt_le_adv_update_data(ad, ARRAY_SIZE(ad),
(struct bt_data*)NULL, (size_t)NULL);
}
K_WORK_DEFINE(adc_sampling_work, adc_sampling_work_handler);
I also tried implementing "work" which submits itself after k_sleep(), but I'm getting the same result.
Also tried building with nCS 2.2.0, same results.
Anyone has an idea what's going on?
Thanks
Emir