ASF ignore CLKPR

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

I have ATMEGA48PA, ASF 3.34.2. I want to use devider on 4 for XTAL (3686400/4=921600Hz) via CLKPR, but SYSCLK_PSDIV_4 don't use CLKPR(

 

conf_board.h

...
/* =====  Select connected clock source */
/*#define  SYSCLK_SOURCE         SYSCLK_SRC_RC16MHZ */
/* #define SYSCLK_SOURCE        SYSCLK_SRC_RC128KHZ */
/* #define SYSCLK_SOURCE        SYSCLK_SRC_TRS16MHZ */
 #define SYSCLK_SOURCE        SYSCLK_SRC_EXTERNAL

/* ===== System Clock Bus Division Options */
#define CONFIG_SYSCLK_PSDIV         SYSCLK_PSDIV_4

#endif

 

conf_board.h

#ifndef CONF_BOARD_H
#define CONF_BOARD_H   

#define BOARD_EXTERNAL_CLK 3686400UL

 

The solvetion:

  CLKPR = ( 1 <<CLKPCE);//сначало разлочим регистр
     CLKPR = 0b10;

 

but it isn't beautiful

 

What I did wrong?

Attachment(s): 

Last Edited: Sat. Aug 12, 2017 - 11:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings and Welcome to AVR Freaks!

 

Do you really have an external 3.68MHz crystal? What are the CLKSEL fuse bits set to? How do you know that the clock is wrong?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sun. Aug 13, 2017 - 12:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't have an ATmega48PA, but according to the simulator, I was able to set the CLKPR to 2 (divide-by-4):

 

 

You didn't show main(), are you calling sysclk_init()?

 

conf_clock.h:

#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED

/* ===== System Clock Source Options */
#define SYSCLK_SRC_RC16MHZ    0
#define SYSCLK_SRC_RC128KHZ   1
#define SYSCLK_SRC_TRS16MHZ   2
#define SYSCLK_SRC_RC32KHZ    3
#define SYSCLK_SRC_XOC16MHZ   4
#define SYSCLK_SRC_EXTERNAL   5

/* =====  Select connected clock source */
#define  SYSCLK_SOURCE         SYSCLK_SRC_EXTERNAL

/* ===== System Clock Bus Division Options */
#define CONFIG_SYSCLK_PSDIV         SYSCLK_PSDIV_4

#endif /* CONF_CLOCK_H_INCLUDED */

 

 

main.c:

#include <asf.h>

int main (void)
{
	sysclk_init();
	board_init();

	do {
		nop();
	} while (1);
}

 

 

EDIT: typo and

 

PS: As Jim mentioned, you have to set the CLKSEL fuses to enable the external clock.

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

Last Edited: Mon. Aug 14, 2017 - 12:26 AM