XOSCRDY bit set when no XT present

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to detect if a crystal is present on the board so I can set the PLL with the internal 2MHz clock and multiply by 16. If the crystal is present, the PLL will be set with XOSC and multiply by 2. The micro is ATXMEGA32A4U.

OSC.XOSCCTRL = 0xCB;    // Crystal type 0.4-16 MHz XTAL - 16K CLK Start Up time
OSC.PLLCTRL = 0xC2;     // XOSC is PLL Source - 2x Factor (32MHz)
OSC.CTRL = OSC_RC2MEN_bm | OSC_RC32MEN_bm | OSC_XOSCEN_bm;
_delay_ms(2);
// Switch to internal 2MHz if crystal fails
if(!testbit(OSC.STATUS,OSC_XOSCRDY_bp)) {   // Check XT ready flag
    OSC.XOSCCTRL = 0x00;    // Disable external oscillators
    OSC.PLLCTRL = 0x10;     // 2MHz is PLL Source - 16x Factor (32MHz)
}
OSC.CTRL = OSC_RC2MEN_bm | OSC_RC32MEN_bm | OSC_PLLEN_bm | OSC_XOSCEN_bm;
_delay_ms(2);
CCPWrite(&CLK.CTRL, CLK_SCLKSEL_PLL_gc);    // Switch to PLL clock
// Clock OK!
OSC.CTRL = OSC_RC32MEN_bm | OSC_PLLEN_bm | OSC_XOSCEN_bm;    // Disable internal 2MHz

When there is no crystal, the micro keeps running with the internal 2MHz, instead of the intended 32MHz.
The problem is that regardless of the presence of the 16MHz crystal, the OSC.XOSCRDY bit gets set.

This used to work on the old ATXMEGA32A4 chip.

Has anyone noticed this? Or perhaps there is a problem with my code?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm waiting for a reply from Atmel support, and I've also told them about the undocumented stuff about the Split Timers...