{"id":102,"date":"2014-02-24T09:28:06","date_gmt":"2014-02-24T09:28:06","guid":{"rendered":"http:\/\/ceptimus.co.uk\/?p=102"},"modified":"2014-02-24T09:28:06","modified_gmt":"2014-02-24T09:28:06","slug":"atmega328p-pu-12mhz-bootloader","status":"publish","type":"post","link":"https:\/\/ceptimus.co.uk\/index.php\/2014\/02\/24\/atmega328p-pu-12mhz-bootloader\/","title":{"rendered":"ATmega328P-PU 12MHz bootloader"},"content":{"rendered":"<p>It took me an embarrassingly long time to get a 328 with a 12MHz crystal working so that it would allow a normal (serial \/ FTDI) upload from the Arduino IDE.<\/p>\n<p>There are a few older guides around but I didn&#8217;t find one that used the newer optiboot bootloader.<\/p>\n<p>If you don&#8217;t want to compile the bootloader yourself, you can download the compiled <a href=\"https:\/\/ceptimus.co.uk\/optiboot_atmega328_12.hex\">optiboot_at328mega_12.hex file from this link<\/a>\u00a0(right-click and and Save (link) as&#8230;) just copy it to your optiboot folder before editing your &#8220;boards.txt&#8221; file as described below.<\/p>\n<p><span style=\"color: #800080;\">If you want to compile the hex file yourself here&#8217;s how:<\/span><\/p>\n<p><span style=\"color: #800080;\">Edit the Makefile in your optiboot folder. On my (Windows 7 64bit) machine using Arduino 1.0.5-r2 this folder was C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\bootloaders\\optiboot<\/span><\/p>\n<p><span style=\"color: #800080;\">Add this section. I put it in after the existing atmega328 sections and before the Sanguino section\u00a0 (note that the -W1, &#8230; shouldn&#8217;t be on a separate line &#8211; it&#8217;s a continuation of the LDSECTIONS line, but this blogging software seems to want to wrap it onto a new line):<\/span><\/p>\n<pre><span style=\"color: #800080;\">atmega328_12: TARGET = atmega328\natmega328_12: MCU_TARGET = atmega328p\natmega328_12: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'\natmega328_12: AVR_FREQ = 12000000L\natmega328_12: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe\natmega328_12: $(PROGRAM)_atmega328_12.hex\natmega328_12: $(PROGRAM)_atmega328_12.lst\n\natmega328_12_isp: atmega328\natmega328_12_isp: TARGET = atmega328\natmega328_12_isp: MCU_TARGET = atmega328p\n# 512 byte boot, SPIEN\natmega328_12_isp: HFUSE = DE\n# Low power xtal (12MHz) 16KCK\/14CK+65ms\natmega328_12_isp: LFUSE = FF\n# 2.7V brownout\natmega328_12_isp: EFUSE = 05\natmega328_12_isp: isp<\/span><\/pre>\n<p><span style=\"color: #800080;\">This is just a copy of the atmega328. section with:<\/span><\/p>\n<ul>\n<li><span style=\"color: #800080;\">the name changed from atmega328. to atmega328_12.<\/span><\/li>\n<li><span style=\"color: #800080;\">the f_cpu parameter changed from 16000000L to 12000000L<\/span><\/li>\n<li><span style=\"color: #800080;\">the two (PROGRAM) lines changed so that the .hex and .lst filenames also have the &#8220;_12&#8221; addition<\/span><\/li>\n<li><span style=\"color: #800080;\">the comment about the 16MHz crystal frequency changed to 12MHz<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #800080;\">Run a command shell as administrator and navigate to the optiboot folder.\u00a0 Enter the following command to compile the new 12MHz optiboot bootloader:<\/span><\/p>\n<p><span style=\"color: #800080;\">omake atmega328_12<\/span><\/p>\n<p>Now edit your boards.txt file.\u00a0 On my machine this was located at C:\\Program Files (x86)\\Arduino\\hardware\\arduino\u00a0 Add this new section at the end &#8211; again this is just a copy of the &#8216;uno&#8217; section with the few obvious edits for frequency and bootloader file.<\/p>\n<pre>##############################################################\n\natmega328bb12.name=ATmega328 12MHz crystal\natmega328bb12.upload.protocol=arduino\natmega328bb12.upload.maximum_size=32256\natmega328bb12.upload.speed=115200\natmega328bb12.bootloader.low_fuses=0xff\natmega328bb12.bootloader.high_fuses=0xde\natmega328bb12.bootloader.extended_fuses=0x05\natmega328bb12.bootloader.path=optiboot\natmega328bb12.bootloader.file=optiboot_atmega328_12.hex\natmega328bb12.bootloader.unlock_bits=0x3F\natmega328bb12.bootloader.lock_bits=0x0F\natmega328bb12.build.mcu=atmega328p\natmega328bb12.build.f_cpu=12000000L\natmega328bb12.build.core=arduino\natmega328bb12.build.variant=standard<\/pre>\n<p>Now launch Arduino, select &#8220;ATmega328 12MHz crystal&#8221; as your board and &#8220;Burn Bootloader&#8221; from the Tools menu.<\/p>\n<p>That&#8217;s it, and you should be up and running with the normal hardware serial port working correctly with the &#8216;Serial&#8217; commands and serial uploading from the Arduino IDE also working correctly.\u00a0 I&#8217;ve seen comments that not all of the timing functions (microsecond delays etc.) work accurately when using a 12MHz crystal and the standard Arduino libraries.\u00a0 I&#8217;ve not investigated that yet; and so far I&#8217;ve not tried using software serial with a 12MHz crystal &#8211; that also may require some tweaking&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It took me an embarrassingly long time to get a 328 with a 12MHz crystal working so that it would allow a normal (serial \/ FTDI) upload from the Arduino IDE. There are a few older guides around but I didn&#8217;t find one that used the newer optiboot bootloader. If you don&#8217;t want to compile [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-102","post","type-post","status-publish","format-standard","hentry","category-arduino","category-programming"],"_links":{"self":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=102"}],"version-history":[{"count":0,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/102\/revisions"}],"wp:attachment":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}