AnsweredAssumed Answered

Enabling Oscillator is causing unhandled interrupt

Question asked by Cecylia Wati on Jul 1, 2016
Latest reply on Jul 4, 2016 by Cecylia Wati


Hi there,


I'm trying to port my code from KSDK 1.0.0 to KSDK 1.3.0, using KDS 3.0.0.  Device is MK22FN256xxx12.

 

We need a precise timer in the ms, which means we can't use "OSA_TimeGetMsec()" since it's drifting too much.  In KSDK 1.0.0 we manually set the RTC registers and read them.  But when I tried to port the code to KSDK 1.3.0, whenever I write 1 to the CR OSCE it will trigger some sort of "WDOG_EWM_IRQHandler()" or Default ISR.

Seems like I'm missing something here... any help is appreciated... Thanks!

 

This is the piece of code:

 

               #define BP_RTC_CR_OSCE       (8U)          /*!< Bit position for RTC_CR_OSCE. */

#define HW_RTC_CR_ADDR(x)    ((x) + 0x10U)

#define BW_RTC_CR_OSCE(x, v) (BITBAND_ACCESS32(HW_RTC_CR_ADDR(x), BP_RTC_CR_OSCE) = (v))

 

void k22f_enable_rtc() {

  // Enable 32.768 kHz oscillator

// The following is the offending line... Ported from KSDK 1.0.0

  BW_RTC_CR_OSCE(RTC, 1);  //or RTC_BWR_CR_OSCE(RTC, 1)  

  // Wait 100ms for oscillator output to settle down

  OSA_TimeDelay(100);

/*  // Disable time counters TSR and TPR before writing

  RTC_BWR_SR_TCE(RTC, 0);

  // Clear the RTC_TPR counter

  HW_RTC_TPR_CLR(RTC, 0xFFFFFFFFU);

  // Write the RTC_TSR with 0 second value

  RTC_WR_TSR(RTC, 0);

  // Enable time counters TSR and TPR after writing

  RTC_BWR_SR_TCE(RTC, 1); */

 

  last_sec = 0;

  last_tpr = 0;

  last_total_ms = 0;

}

 

This is the result.

Screenshot (70).png

Outcomes