Tiny817 unable to set clock prescaler

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

There is probably something I'm doing wrong trying to set a 1MHz clock.

 

The main clock fuse is set for 16 Mhz and the divider SHOULD BE set @16 but it is not happening.

 

The LOCKEN bit is not set and temp (r24 on the right pane) has the correct value but it is not being written to MCLKCTRLB surprise
 

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Thu. Nov 24, 2016 - 09:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

11.5.6. Configuration Change Protection
This peripheral has registers that are under Configuration Change Protection (CCP). In order to write to
these, a certain key must be written to the CPU.CCP register first, followed by a write access to the
protected bits within four CPU instructions.

It has the same sort of protection as Xmega, Tiny1634, ...

 

Untested.

 

David.

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

11.5.6. Configuration Change Protection

hmm my November datasheet only goes up to 11.5.1, which version of the datasheet do you have?

 

I wrote the correct value to the CPU_CCP and it's all working, thank you.

 

Maybe a few sprinkled warnings in the datasheet about this would help.

 

Found this

 

8.5.7. CCP - Configuration Change Protection
System critical I/O register settings are protected from accidental modification. Flash self-programming
(via store to NVM controller) is protected from accidental execution. This is handled globally by the
configuration change protection (CCP) register.
Changes to the protected I/O registers or bits, or execution of protected instructions, are only possible
after the CPU writes a signature to the CCP register. The different signatures are listed in the description
of the CCP register (CPU.CCP).
There are two modes of operation: one for protected I/O registers, and one for the protected selfprogramming.
Related Links
CCP on page 55
 

 

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

You need to write 0xD8 to CCP BEFORE you can set the clock pre-scaler.

 

 

ldi temp, 0xD8
sts CPU_CCP, temp
;then your code
ldi temp, (CLKCTRL_PDIV1_bm | CLKCTRL_PDIV0_bm | CLK_PEN_bm )
...
...

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ldi temp, 0xD8

Hey Syd you should not foster bad habits in people by using "magic numbers" wink

 

Didn't you see how's done above?

 

;Set clock to 1 MHz
	ldi		temp, (CLKCTRL_PDIV1_bm | CLKCTRL_PDIV0_bm) | CLKCTRL_PEN_bm	; Div 16 and enable divider
	ldi		temp1, CPU_CCP_IOREG_gc  ;******
	sts		CPU_CCP, temp1           ;******
	sts		CLKCTRL_MCLKCTRLB, temp

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Similar via Atmel START in

  • ccp.S
  • clkctrl.c

 

Atmel

ATtiny417 / ATtiny814 / ATtiny816 / ATtiny817

Sequence for Write Operation to Configuration Change Protected I/O Registers

http://atmel-studio-doc.s3-website-us-east-1.amazonaws.com/webhelp/GUID-B7A2E5C2-FD58-4610-A9E0-CF7F841E9D39-en-US-4/index.html?GUID-7A632D98-AC0C-446B-A780-6EB8B5134948

 

/* Prescaler enable: enabled */
/* Prescaler enable: enabled */

"Dare to be naïve." - Buckminster Fuller

Last Edited: Fri. Nov 25, 2016 - 07:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks this thread really helped. I had missed the "protected by the Configuration Change Protection Mechanism​" line in the datasheet.

The following works in C:

 CCP = CCP_IOREG_gc;
 CLKCTRL_MCLKCTRLB = 0x00;