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

using ANT with RTC timers - softdevice conflicting with LFClk

We are trying to get the ANT feature to run based on RTC as follows:

a. Timer RTC0 or 1 (1 for this example - tick is disabled, compare is on.) b. Timer initialized (all works very well). c. Start timer - go for 10-second IRQ in compart cc[0] - works great.

The Clock startup works ok and IRQ for RTC1 enables ok (taken from the example codes)..

NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_LFCLKSRC_Xtal << CLOCK_LFCLKSRC_LFCLKSRC_Pos); NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; NRF_CLOCK->TASKS_LFCLKSTART = 1; while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}

NRF_POWER->PERPOWER |= (POWER_PERPOWER_RTC1_Power << POWER_PERPOWER_RTC1_Pos);

while ((NRF_POWER->PERRDY & POWER_PERRDY_RTC1_Msk)!= (POWER_PERRDY_RTC1_Ready << POWER_PERRDY_RTC1_Pos)) { }

NVIC_EnableIRQ(RTC1_IRQn); NRF_RTC1->PRESCALER = COUNTER_PRESCALER;
NRF_RTC1->CC[0] = COMPARE_COUNTERTIME * RTC_FREQUENCY;

The problems lies where we try to initialize the ANT - particularly on the softdevice.. We consistently get a hard fault when the softdevice enable is attempted.

return_value = nrf_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, softdevice_assert_callback);

if (return_value != NRF_SUCCESS) yellow_error();

return_value = nrf_nvic_SetPriority(PROTOCOL_EVENT_IRQn, NRF_APP_PRIORITY_LOW); if (return_value != NRF_SUCCESS) yellow_error();

return_value = nrf_nvic_EnableIRQ(PROTOCOL_EVENT_IRQn); if (return_value != NRF_SUCCESS) purple_error();

return_value != ant_channel_assign(CHANNEL_0,
CHANNEL_TYPE_SHARED_MASTER, ANT_CHANNEL_DEFAULT_NETWORK, EXT_PARAM_FAST_START_MODE); if (return_value != NRF_SUCCESS) purple_error(); return_value != ant_channel_id_set(CHANNEL_0, CHANNEL_0_CHAN_ID_DEV_NUM, CHANNEL_0_CHAN_ID_DEV_TYPE, CHANNEL_0_CHAN_ID_TRANS_TYPE); if (return_value != NRF_SUCCESS) purple_error();

return_value = ant_channel_open(CHANNEL_0);

WE NOTE THE FOLLOWING IN THE .SDM.H FILE. REGARDING nrf_softdevice_enable ROUTINE - SPECIFICALLY, THE NOTE REGARDING THE LfClk "already running."

@brief Enables the softdevice and by extension the protocol stack. *

  • Idempotent function to enable the softdevice.
  • @note Some care must be taken if a low frequency clock source is already running when calling this function: If the LF clock has a different source then the one currently running, it will be stopped. Then, the new clock source will be started.
  • @note This function has no effect when returning with an error.
  • @post If return code is ::NRF_SUCCESS
  •   - SoC library and protocol stack APIs are made available
    
  •   - A portion of RAM will be unavailable (see the relevant SDS documentation)
    
  •   - Some peripherals will be unavailable or available only through the SoC API (see the relevant SDS documentation)
    
  •   - Interrupts will not arrive from protected peripherals or interrupts
    
  •   - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the softdevice.
    
  •   - Interrupt latency may be affected by the softdevice  (see your device's documentation)
    
  •   - Chosen LF clock source will be running
    
  • @param clock_source Low frequency clock source and accuracy. (Note: In the case of XTAL source, the PPM accuracy of the chosen clock source must be greater than or equal to the actual characteristics of your XTAL clock).
  • @param assertion_handler Callback for softdevice assertions.

We've used both of the features (independently) with no problems, but when they are both enabled, one runs over the other...

What is the correct way to use the RTC (or other) timer to time execution cycles which include ANT involvement?

Can they both be enabled at the same time? Examples!!???

If not: how can one use a Timer -and-/-or- ANT interrupt to wake momma back up?

Thank you!!! roger

Parents
  • HRM project, unless i misread, is implementing UART - which is of no interest. I think we missed the boat here.

    We just want a process for one of the following (either is ok)..

    a. bring up a timing mechanism for a period of 1-20 minutes.. at comparator match, release the logic to bring up ANT, do some ant stuff, then, if needed shut ant down and restart the timer for the next cycle...

    --- or -- ideally!

    b. bring up ANT and timer together, allowing interrupt from any listening OR comparator, them handle the particular interrupts from Timer or Protocol events through IRQ routines...

    Is this possible??? HOW? Specific Example???

    tks!

Reply
  • HRM project, unless i misread, is implementing UART - which is of no interest. I think we missed the boat here.

    We just want a process for one of the following (either is ok)..

    a. bring up a timing mechanism for a period of 1-20 minutes.. at comparator match, release the logic to bring up ANT, do some ant stuff, then, if needed shut ant down and restart the timer for the next cycle...

    --- or -- ideally!

    b. bring up ANT and timer together, allowing interrupt from any listening OR comparator, them handle the particular interrupts from Timer or Protocol events through IRQ routines...

    Is this possible??? HOW? Specific Example???

    tks!

Children
  • You're right that the HRM example (and several of the other examples) implement some debug output over UART, but I don't see how that makes the example irrelevant. It still shows both how to use RTC for application timing and how to interface with the softdevice, both of which should be useful to your application.

    There is no specific example doing exactly what you need, but if you look at the modules available, especially app_timer, how they are used in the examples and make sure that you understand how the softdevice concept works, there shouldn't be any problems doing what you want.

    I'd recommend you to use app_timer for your needs, since that gives the possibility of having multiple application timers, but if you instead prefer to use RTC1 directly, you can look at the SDM example. Both use the RTC timer at the same time as using the softdevice, which should be no problem at all if you comply with the requirements from the SoftDevice specification and the Reference Manual.

Related