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
  • 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.
Reply
  • 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.
Children
Related