Configuration Change Protection (CCP)

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

Is this how to write to protected I/O registers?  Is it ok to write to the CCP register again before the 4 clock cycles have elapsed?

 

Main: ldi         Temp2,0xD8               ;Load Temp2 with the unprotect code.

 

        sts        CPU_CCP,Temp2         ;Disable I/O write protection.
        ldi         Temp1,0b00000010     ;External 32kHz oscillator.
        sts        CLKCTRL_MCLKCTRLA,Temp1

 

        sts        CPU_CCP,Temp2         ;Disable I/O write protection.
        ldi         Temp1,0b00000000     ;No prescale on the 32kHz clock.
        sts        CLKCTRL_MCLKCTRLB,Temp1

 

        sts        CPU_CCP,Temp2         ;Disable I/O write protection.
        ldi         Temp1,0b00000011     ;Enable clock always. 30 msec clock startup time.
        sts        CLKCTRL_XOSC32KCTRLA,Temp1

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

Do the LDIs first then two consecutive STS just to be sure. Oh and depending on context you might want to consider the possibility of being interrupted.

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

The "key" write to the CPU_CCP and the write to the controlled access register must be within a very small number (4?) cpu clock cycles. Looks to me like there are hardly any alternatives to what you are doing in assembler except what Cliff describes. I would define TampA, TempB, and TempC, preload those before hand, then to the key write, immediately followed by the register write. OR, maybe, saving some registers,

 

Main:   ldi        Temp2,0xD8            ;Load Temp2 with the unprotect code.

        ldi        Temp1,0b00000010      ;External 32kHz oscillator.
        sts        CPU_CCP,Temp2         ;Disable I/O write protection.
        sts        CLKCTRL_MCLKCTRLA,Temp1

        ldi        Temp1,0b00000000      ;No prescale on the 32kHz clock.
        sts        CPU_CCP,Temp2         ;Disable I/O write protection.
        sts        CLKCTRL_MCLKCTRLB,Temp1

        ldi        Temp1,0b00000011      ;Enable clock always. 30 msec clock startup time.
        sts        CPU_CCP,Temp2         ;Disable I/O write protection.
        sts        CLKCTRL_XOSC32KCTRLA,Temp1

 

By the way, this is the  listing you get when you click the "<>" icon up in the toolbar.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Sat. Feb 22, 2020 - 10:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.

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

clawson wrote:
Oh and depending on context you might want to consider the possibility of being interrupted.

 

The Attiny817 data sheet says:

 

 

Now this is for the tiny817 so I imagine other chips could be different.  Is that what you meant by context?

 

Letting the smoke out since 1978