Search code examples
cavrfuseatmega

how to configure CKDIV8 fuse on AVR programming


I use atmega168a and configure fuse on Tools > device programming > AVR dragon > fuses > (click on) CKDIV8 to set it to 8 MHz internal clock.

what piece of code do I need to add to my C code to be able to set that fuse?


Solution

    • If you set the fuse externally, as a separate step, you don't need any further code in C.

    • If you set the fuse programmatically, you don't need to set the fuse externally. Now (each) program decides, at run-time. This code is for atmega32u2:

    CLKPR = 1 << CLKPCE;
    // Set prescaler to 1
    CLKPR = 0;


    In both cases, you should set F_CPU:

    #define F_CPU 8000000ul
    

    in your source or even better as CFLAGS

    CFLAGS += -DF_CPU=8000000ul

    in your Makefile, so that others knows about the core frequency: _delay_ms in <util/delay.h>, for example.