This is the C code that I currently use to enable the 32MHz clock:
CCP = CCP_IOREG_gc;
OSC.CTRL = OSC_RC32MEN_bm;
while(!(OSC.STATUS & OSC_RC32MRDY_bm));
CCP = CCP_IOREG_gc;
CLK.CTRL = CLK_SCLKSEL_RC32M_gc;
But this code needs to be compiled with some form of optimization enabled (-Os
is suggested). Is there a way to do this in assembly without optimizations enabled?
Best Answer
Sure, if you are using Atmel Studio, the easiest way to do this is to compile your project using
-Os
and then view the contents of the*.lss
file inside thedebug
directory. This file contains the C code in conjunction with the compiled assembly code:Using the information from this file, you can modify your C code to this:
This inline assembly was tested working against an
ATXMEGA32A4U
with no optimizations enabled. Alternatively, you could add an assembly file to your project and create a function in assembler, but this requires no knowledge of assembly to implement.If you are interested in the avr instruction set, more information can be found here.