I know this probably isn't something a newbie does but I'm trying to learn as much as I can and will need to know this eventually.
I'm read the following tutorials on Fuse Settings in relation to changing the clock frequency on my ATmega328P Xplained Mini board.
Introduction to Fuses (http://www.ladyada.net/learn/avr/fuses.html)
Section 9 of the chip datasheet (http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf)
Section 2.2 of User Guide for ATmega328P Xplained mini (http://www.atmel.com/Images/Atmel-42287-ATmega328P-Xplained-Mini-User-Guide_UserGuide.pdf)
WHAT I'M TRYING TO DO:
Eventually, i'm going to be designing a board that uses a real time clock for input into a ATmega328P chip. So I would like to gain relevant knowledge with fuse settings "safely" using my Xplained Mini. Some major concepts I can think of are as follows...
1.) How to change the fuses to select different clock frequencies by Atmel Studio 6.2 tools or by direct assembly coding
2.) Knowing what fuses to change such as CKSEL0 through CKSEL3, SUT0 throughSUT1, and others i'm not aware
3.) How to change the pre scale value.
4.) How to verify/test what fuses are previously set and how I might trouble shoot with using a scope
MY CURRENT SETUP AND WHAT I'VE TRIED
In the User Guide of my board under section 2.2(Clock Distribution) it says the following "The ATmega32U4 (mEDBG) has an external 16MHz XTAL. The ATmega32U4 provides an external 16MHz clock to the ATmega328P (Target).".
I verified this by looking at the design documentation (see attachment "Design") I'll go ahead and attach the complete Design PDF in case you want a more detailed look. The 32U chip must be in charge of programming the 328P chip and providing the external 16MHz clock to the target (328P chip) In the design I see that this external clock is connect to the target (328P) on PB6 TOSC1/XTAL1. From reading section 9.2 in the 328P datasheet under Table 9-1(Device Clocking Options Select) I assume that the External Clock is being used. I don't understand when it defines a column as CKSEL3...0 and for external clock it says 0000 is the value set for CKSEL3...0. That confuses me. I guess i've been reading registers these past few days so i'm expecting something like bit 0 bit1 ect ect. Not understanding this fuse nomenclature. I've opened up the device file M328PDEF.INC and found a few interesting sections. I see there is a reference variable I can use to set them but still unsure and nervous on how to do it using code and where to exactly put this code in my .asm file. These declarations are as follows in case your wondering what I'm talking about...
; OSCCAL - Oscillator Calibration Value .equ CAL0 = 0 ; Oscillator Calibration Value Bit0 .equ CAL1 = 1 ; Oscillator Calibration Value Bit1 .equ CAL2 = 2 ; Oscillator Calibration Value Bit2 .equ CAL3 = 3 ; Oscillator Calibration Value Bit3 .equ CAL4 = 4 ; Oscillator Calibration Value Bit4 .equ CAL5 = 5 ; Oscillator Calibration Value Bit5 .equ CAL6 = 6 ; Oscillator Calibration Value Bit6 .equ CAL7 = 7 ; Oscillator Calibration Value Bit7 ; CLKPR - Clock Prescale Register .equ CLKPS0 = 0 ; Clock Prescaler Select Bit 0 .equ CLKPS1 = 1 ; Clock Prescaler Select Bit 1 .equ CLKPS2 = 2 ; Clock Prescaler Select Bit 2 .equ CLKPS3 = 3 ; Clock Prescaler Select Bit 3 .equ CLKPCE = 7 ; Clock Prescaler Change Enable ; ***** FUSES ************************************************************ ; LOW fuse bits .equ CKSEL0 = 0 ; Select Clock Source .equ CKSEL1 = 1 ; Select Clock Source .equ CKSEL2 = 2 ; Select Clock Source .equ CKSEL3 = 3 ; Select Clock Source .equ SUT0 = 4 ; Select start-up time .equ SUT1 = 5 ; Select start-up time .equ CKOUT = 6 ; Clock output .equ CKDIV8 = 7 ; Divide clock by 8 ; HIGH fuse bits .equ BOOTRST = 0 ; Select reset vector .equ BOOTSZ0 = 1 ; Select boot size .equ BOOTSZ1 = 2 ; Select boot size .equ EESAVE = 3 ; EEPROM memory is preserved through chip erase .equ WDTON = 4 ; Watchdog Timer Always On .equ SPIEN = 5 ; Enable Serial programming and Data Downloading .equ DWEN = 6 ; debugWIRE Enable .equ RSTDISBL = 7 ; External reset disable ; EXTENDED fuse bits .equ BODLEVEL0 = 0 ; Brown-out Detector trigger level .equ BODLEVEL1 = 1 ; Brown-out Detector trigger level .equ BODLEVEL2 = 2 ; Brown-out Detector trigger level
I've tried searching online tutorials on changing the fuses or some example code on doing this in assembly code but can't find anything helpful. It's so frustrating reading a technical document as a newbie or tutorial for the first time. I'm come across two websites that should be helpful but like I just said i'm having a terrible time understanding how to proceed. First website (http://www.engbedded.com/fusecalc) from what i'm gathering is asking the user to input what their wanting to set the clock to then outputs various settings that would need to be implented somewhere in code or through some GUI tool ?! I ASSUME !?. I cannot find any tool in Atmel Studio 6.2 or example code on how to set these fuses. I did a search and found the following website (http://www.atmel.com/webdoc/atmelstudio/atmelstudio.programmingdialog.fuses.html) but I do not see this option when i open up project properties (see attachment "MyOptions").
Can someone get me started here or at least point me to some tutorials I have not read. At the very least I would like to verify/test what I currently have and what my fuses are set too. Maybe knowing that I can at least work backwards and figure out how to set the appropriate fuses. I hear setting these fuses is like walking on the edge of a knife and those that attempt it without understanding of whats going can really mess up their board.