RTT with Keil RTX not working properly

Discussion about SAM7 Series and ARM7TDMI based products.

Moderator: nferre

Viktor
Posts: 1
Joined: Fri Feb 17, 2017 6:05 pm

RTT with Keil RTX not working properly

Mon Feb 20, 2017 6:17 pm

Hello everyone.
I'm using at91sam7s512 with Keil RTX RTOS, and i want to use RTT, to have real time clock.
This is my first project whith this MCU. And I'm stuck.

RTT interrups work but with unexpexted period about 0.2 sec instead of 1 second.

can anybody help me?

Code: Select all

void LowLevelInit (void){
    unsigned char i;

        // Initialize main oscillator
    AT91C_BASE_PMC->PMC_MOR = BOARD_OSCOUNT | AT91C_CKGR_MOSCEN;
			AT91C_BASE_PMC->PMC_MOR = 0x121;
    
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS));

    // Initialize PLL at 96MHz (96.109) and USB clock to 48MHz
    AT91C_BASE_PMC->PMC_PLLR = BOARD_USBDIV | BOARD_CKGR_PLL | BOARD_PLLCOU | BOARD_MUL | BOARD_DIV;

    AT91C_BASE_PMC->PMC_PLLR = (( AT91C_CKGR_DIV & 0x05) | (AT91C_CKGR_PLLCOUNT & (16<<8)) |
																(AT91C_CKGR_MUL & (25<<16)));

    // Wait for the master clock if it was already initialized
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

    // Switch to slow clock + prescaler
    AT91C_BASE_PMC->PMC_MCKR = BOARD_PRESCALER;
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

    // Switch to fast clock + prescaler
    AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
    while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY));

 // Initialize AIC
    AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF;
    AT91C_BASE_AIC->AIC_SVR[0] = 0;
    for (i = 1; i < 31; i++) {

        AT91C_BASE_AIC->AIC_SVR[i] = 0;
    }
    AT91C_BASE_AIC->AIC_SPU =0;

    // Unstack nested interrupts
    for (i = 0; i < 8 ; i++) {
        AT91C_BASE_AIC->AIC_EOICR = 0;
    }
	
}

void ISR_Rtt (void) __irq {
  unsigned int status;

    // Get RTT status
    status = RTT_GetStatus(AT91C_BASE_RTTC);

    // Time has changed, refresh display
    if ((status & AT91C_RTTC_RTTINC) == AT91C_RTTC_RTTINC) {
        aparat_cond.timer ++;
    }
	
    AT91C_BASE_AIC->AIC_EOICR = 0;
}

void ConfigureRtt(void){
    unsigned int previousTime;

    // Configure RTT for a 1 second tick interrupt
    RTT_SetPrescaler(AT91C_BASE_RTTC, 32768);
    previousTime = RTT_GetTime(AT91C_BASE_RTTC);
    while (previousTime == RTT_GetTime(AT91C_BASE_RTTC));

    // Enable RTT interrupt
    AIC_ConfigureIT(AT91C_ID_SYS, 0, ( void (*)(void))ISR_Rtt);
    AIC_EnableIT(AT91C_ID_SYS);
    RTT_EnableIT(AT91C_BASE_RTTC, AT91C_RTTC_RTTINCIEN);
}

int main(void){  
	LowLevelInit();
	/*enable pio */
	*AT91C_PMC_PCER = (1 << AT91C_ID_PIOA);
		
	io_init();
	ConfigureRtt();	
	
	os_sys_init (init); 
}

Return to “SAM7 ARM7TDMI MCU”

Who is online

Users browsing this forum: No registered users and 2 guests