Hallo,
Ich habe ein Problem mit meinem Xmega 32a4:
Ich wollte heute die RTC ausprobieren, was in einem Standalone Programm auch funktionierd hat.
Dann hab ich sie in mein Programm eingebaut und plötzlich geht nichts mehr.
Die RTC löscht das Busy Flag nicht mehr, also Fehler suche:
Jetzt bin ich so weit, das ich den Fehler auf die PLL eingrenzen konnte.
In meinem Hauptprogramm verwende ich diese um aus meinem 16MHz externem Quarz die 32 MHz für den uc bereitzustellen.
Verwende ich eine andere Taktquelle,(2MH intern/32MHz intern/16MHz Quarz) so macht sie was sie soll, nur bei der PLL bleibt sie stehen.
Wie kann das sein ?
Die RTC verwendet doch eine ganz andere Taktquelle(bei mir 32khz intern) ?
Ich habe im Datenblatt keinen Hinweis der gleichen gefunden.
Mein Hauptprogramm:
Code:
// Init clocking (32Mhz generated from 16Mhz external)
    // Init clocking (32khz generated internaly for RTC)
    Clock_init(CLOCK_EXTERNAL);
    PLL_init();
    Clock_init_rtc();
    // Wait and init RTC clock
    while ( RTC_Busy() ){};
    RTC_Initialize( 1024, 0, 0, RTC_PRESCALER_DIV1_gc );
    RTC_SetIntLevels( RTC_OVFINTLVL_LO_gc, RTC_COMPINTLVL_OFF_gc );
    // Enable all interrupt levels
    PMIC.CTRL |= PMIC_LOLVLEN_bm;
    // Enable global interrupts
    sei();
    // Set Led as output
    PORTE.DIRSET=(1<<PIN3);
    while(1)
    {        
    }            
}

/*! \brief RTC overflow interrupt service routine.
 *
 *    Called every second
 */
ISR(RTC_OVF_vect)
{
    PORTE.OUTTGL=(1<<PIN3);
}
Meine Clock routinen:
Code:
void Clock_init(uint8_t source)
{
    if(source==CLOCK_INTERNAL_2){
        /*Internal 32MHz */
        OSC.CTRL |= OSC_RC2MEN_bm;
        while(!(OSC.STATUS & OSC_RC2MRDY_bm));
        CCP = CCP_IOREG_gc;
        CLK.CTRL = CLK_SCLKSEL_RC2M_gc;
    }else if(source==CLOCK_INTERNAL_32){
        /*Internal 32MHz */
        OSC.CTRL |= OSC_RC32MEN_bm;
        while(!(OSC.STATUS & OSC_RC32MRDY_bm));
        CCP = CCP_IOREG_gc;
        CLK.CTRL = CLK_SCLKSEL_RC32M_gc;
    }else if(source==CLOCK_EXTERNAL){
        /* External Clock */
        OSC_XOSCCTRL = OSC_XOSCSEL_XTAL_16KCLK_gc | OSC_FRQRANGE_12TO16_gc;
        OSC.CTRL |= OSC_XOSCEN_bm;
        while(!(OSC.STATUS & OSC_XOSCRDY_bm));
        CCP = CCP_IOREG_gc;
        CLK.CTRL = CLK_SCLKSEL_XOSC_gc;
    }
    CCP = CCP_IOREG_gc;
    CLK.PSCTRL=0x00;
}

void PLL_init()
{
    OSC.PLLCTRL = OSC_PLLSRC_XOSC_gc | 0x08;
    OSC.CTRL |= OSC_PLLEN_bm;
    while (!(OSC.STATUS & OSC_PLLRDY_bm));
    CCP = CCP_IOREG_gc;
    CLK.PSCTRL=0x03;
    CCP = CCP_IOREG_gc;
    CLK.CTRL = CLK_SCLKSEL_PLL_gc;
}

/* \brief Initiates the 32khz clock needed for the RTC.
*/
void Clock_init_rtc()
{
    /* Turn on internal 32kHz. */
    OSC.CTRL |= OSC_RC32KEN_bm;

    do {
        /* Wait for the 32kHz oscillator to stabilize. */
    } while ( ( OSC.STATUS & OSC_RC32KRDY_bm ) == 0);


    /* Set internal 32kHz oscillator as clock source for RTC. */
    CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm;
}
Was mache ich an der PLL falsch ?
Die RTC Routinen sind aus der Atmel Appnote und funktionieren auch.

MFG Thalhammer