I am using v7.0.1 S132 SDK on the nRF52832 processor for BlueTooth Light coded in Segger.
I have a high speed output (50uS) to drive an external device using an internal timer (timer[3]).
There seems to be jitter on the GPIO output.
Many posts seem to refer to forcing the use of the external 32MHz crystal using sd_clock_hfclk_request();
But querying the state using sd_clock_hfclk_is_running(p_is_running); never returns true.
I know the HF clock is running because I'm using the 16MHz clock for the timer (and using the radio to send BLE pkts).
How do I know which clock (INT or XO) is being used?
How do I force it to use the external 32MHz crystal?
Code Snippets
NOTE: The timer works but has Jitter
==============================================================================
// Main() startup calls for BLE using SDK S132 v7.0.1
// 1) HFXO Startup fails here
// Basic startup
log_init();
timers_init(); // Application timers in OS (1Hz)
buttons_leds_init(&erase_bonds);
power_management_init();
// BLE Startup
ble_stack_init();
memset(&mac_addr, 0, sizeof(mac_addr));
sd_ble_gap_addr_get(&mac_addr);
gap_params_init();
gatt_init();
advertising_init();
services_init();
conn_params_init();
peer_manager_init();
init_my_timer();
// 2) HFXO Startup fails here
application_timers_start();
advertising_start(erase_bonds);
// 3) HFXO Startup fails here
==============================================================================
// Attempt to start the HFClock using HFXO
// Fails in all 3 locations above
// The while loop never quits ???
static uint32_t * p_is_running;
sd_clock_hfclk_is_running(p_is_running);
if (!p_is_running){
//NRF_CLOCK->TASKS_HFCLKSTART = 1;
sd_clock_hfclk_request(); // Force the use of the external HFXO?
while (!p_is_running)
sd_clock_hfclk_is_running(p_is_running);
}
==============================================================================
// Timer init code
static const nrf_drv_timer_t m_timer3 = NRF_DRV_TIMER_INSTANCE(3); // Internal timer[3]
nrf_drv_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
void init_my_timer()
{
timer_cfg.frequency = NRF_TIMER_FREQ_16MHz; // Use the HF Clock
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
err_code = nrfx_timer_init(&m_timer3, &timer_cfg, timer3_event_handler);
APP_ERROR_CHECK(err_code);
nrfx_timer_extended_compare(&m_timer3,
NRF_TIMER_CC_CHANNEL0,
nrf_drv_timer_us_to_ticks(&m_timer3, 50) // Init 50uS timer NOTE: This is off by about 2uS
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
true);
}
==============================================================================
// Note I can use buttons to start/stop this timer on the nRF52 SD
nrfx_timer_enable(&m_timer3); // Start the timer
nrfx_timer_disable(&m_timer3); // Stop the timer
==============================================================================
// Timer IRQ handler
static bool timer3_trig_state = false;
static void timer3_event_handler(nrf_timer_event_t event_type, void * p_context)
{
// Toggle PO.13 (D2) every 50uS
if (timer3_trig_state){
*gpio_outclr_cfg = 1UL<<ARDUINO_2_PIN;
timer3_trig_state = false;
} else {
*gpio_outset_cfg = 1UL<<ARDUINO_2_PIN;
timer3_trig_state = true;
}
}

