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

  • -- note that in the code the "Colored" errors (yellow_error, etc) are produced by RGB leds on our pcb..

  • Update - more surprises! We moved over to HF timer to try it there.. Timer0 works like a charm but..could not get the ANT to start back up.

    We removed ALL timer configs and startups (and all references to the timer) and cannot get the softdevice to start back up. Went back to prior versions of the source without the timer0 with no luck..

    we see: while trying to start up the ant...

    1. enabling the softdevice error code %d4097 (base + x1)
    2. the nvic_set_prior... produces 0x1 error.
    3. subsequent enable_irq.. gets %d 0x2 code..

    ?? ANT THOUGHTS?? It seems like the IRQ evaporated??

    Is there an example of running ANT on a timer cycle??

    Thank you!!

  • Update: 2013.10.30: 18:00 cdt/us

    Per discussion w/ NS, I understand that the examples using direct write to registers (in many) cases clobber the SD workings. I understand that once the S210 is enabled, many of the calls in the examples are disqualified per direct writes (as we did above) to registers and may cause fault, interrups, or disabling of the SD processes. NS explains that examples that do NOT use softdevice should be compatible with other examples that do NOT use SD. If the SD is being enabled, the correct means to write to the comfig/starts/etc is to use SD calls... But the examples to not typically show how to do them.

    So - to rephrase the questions per above: Is there a correct means to run rtc/timers in concert w/ the ANT stuff where they both can exist and (a. any or (b. either interrupt can be used to process cause for interrupt??

    Please explain & show??

    Thank you!

  • I'm having a little trouble understanding the exact problem or question here, but I have a couple of comments:

    1. As you've found out, when the softdevice is enabled, some peripherals are either restricted or blocked. Those that are blocked can not be used at all when the softdevice is enabled, while the ones that are restricted can be used only through the softdevice's API. The S210 SoftDevice Specification provides a complete list of which peripherals are open, blocked and restricted.

    2. You seem to be using a very old version of the SDK. I'd strongly recommend you to upgrade to the latest version as soon as possible., which is currently 4.4.1. To ensure compatibility with all chip revisions, you should make sure to remove all references to the PERPOWER/PERRDY registers.

    3. The latest versions of the SDK also includes a number of examples all showing how to use a timer with the softdevice. For example the ant_hrm_tx project uses RTC1 to simulate a pulse event. I guess this should be a good example of how to use timers with the softdevice.

    Edit: Specifically take a look at nrf51422\Board\nrf6310\ant\ant_hrm\hrm_tx\hrm_tx.c file, and the project it's part of.

    Considering point 1 above, if you need to use a 16 MHz timer, make sure to use TIMER1 or TIMER2 and not TIMER0.

    1. When calling softdevice functions, they may return errors in case something is not as expected. Always check error codes on all softdevice function calls! The header file definitions of the softdevice functions lists all the errors that can be returned, along with a short description of each one. If you have an error code that you want to relate to a define, you should take a look at ant_error.h, nrf_error.h, , nrf_error_sdm.h and nrf_error_soc.h, which contains all the error defines.
  • 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!

Related