<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Beck&#039;s Blog &#187; Microcontroller</title>
	<atom:link href="http://davidbeckblog.com/tag/microcontroller/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidbeckblog.com</link>
	<description>The ramblings of an obsessed programmer</description>
	<lastBuildDate>Thu, 22 Jul 2010 18:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>AVR and Xcode</title>
		<link>http://davidbeckblog.com/2009/10/avr-and-xcode/</link>
		<comments>http://davidbeckblog.com/2009/10/avr-and-xcode/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 23:05:31 +0000</pubDate>
		<dc:creator>David Beck</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://davidbeckblog.com/?p=130</guid>
		<description><![CDATA[I recently purchased the beginning embedded electronics kit from SparkFun Electronics. It is a kit that include everything to start programming AVR microcontrollers. A microcontroller lets you control the most simple, physical things, like an LED or a motor. Given my lust for control, you can see why this has quickly become my latest obsessive [...]]]></description>
			<content:encoded><![CDATA[<p>I recently purchased the <a href="http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=57" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=57&amp;referer=');">beginning embedded electronics</a> kit from <a href="http://sparkfun.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/sparkfun.com?referer=');">SparkFun Electronics</a>. It is a kit that include everything to start programming AVR microcontrollers. A microcontroller lets you control the most simple, physical things, like an LED or a motor. Given my lust for control, you can see why this has quickly become my latest obsessive hobby.</p>
<p>The problem is that I want to be able to program the micro with my Mac, which presented a few problems. Here is how I got it working with Xcode on my Mac.<br />
<span id="more-130"></span><br />
The first step was getting the programmer to work.</p>
<p>The only problem? The kit screams Windows. By default it includes a <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=13" onclick="pageTracker._trackPageview('/outgoing/www.sparkfun.com/commerce/product_info.php?products_id=13&amp;referer=');">parallel programer</a>. The last time I had a computer with a parallel port was&#8230; well it was when I had a PC. Not only that but SparkFun only carries Windows compatible <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8702" onclick="pageTracker._trackPageview('/outgoing/www.sparkfun.com/commerce/product_info.php?products_id=8702&amp;referer=');">USB programmers</a> (a programmer in this case is a device that transfers your code to the chip, not the skinny kid from high school with a Redbull IV in him). In fact, there are almost no AVR programmers that are Mac compatible.</p>
<p>Not knowing the days of frustration that I was getting myself into, I bought the <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8702" onclick="pageTracker._trackPageview('/outgoing/www.sparkfun.com/commerce/product_info.php?products_id=8702&amp;referer=');">STK500 USB programmer</a>. Other options would be the now discontinued <a href="http://www.pololu.com/catalog/product/740" onclick="pageTracker._trackPageview('/outgoing/www.pololu.com/catalog/product/740?referer=');">Pololu programmer</a>, or build it yourself.</p>
<p>Luckily, <a href="http://www.olimex.com/" onclick="pageTracker._trackPageview('/outgoing/www.olimex.com/?referer=');">Olimex</a>, the company that made the STK500 USB programmer, has released an <a href="http://www.olimex.com/dev/soft/avr/AVR-ISP500/AvrIspFwUpdate_1_0_0_8.zip" onclick="pageTracker._trackPageview('/outgoing/www.olimex.com/dev/soft/avr/AVR-ISP500/AvrIspFwUpdate_1_0_0_8.zip?referer=');">update</a> that makes it Mac compatible. You can find info and instructions on how to install it on <a href="http://www.olimex.com/dev/avr-isp500.html" onclick="pageTracker._trackPageview('/outgoing/www.olimex.com/dev/avr-isp500.html?referer=');">their product page</a>. Be sure to follow the instructions <em>exactly</em>. You will need a Windows computer to do the upgrade. It worked fine in <a href="http://www.amazon.com/gp/product/B002Q72JB8?ie=UTF8&amp;tag=dabesbl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B002Q72JB8" onclick="pageTracker._trackPageview('/outgoing/www.amazon.com/gp/product/B002Q72JB8?ie=UTF8_amp_tag=dabesbl-20_amp_linkCode=as2_amp_camp=1789_amp_creative=390957_amp_creativeASIN=B002Q72JB8&amp;referer=');">VMWare Fusion</a>.</p>
<p>The next step was to get the build tools woking in Mac OS X. These are the programs that will compile your code and transfer it to the microcontroller.</p>
<p>The easiest way to get the tools needed is to get <a href="http://www.obdev.at/products/crosspack/index.html" onclick="pageTracker._trackPageview('/outgoing/www.obdev.at/products/crosspack/index.html?referer=');">CrossPack</a>. CrossPack includes all the tools necessary to build and upload your projects. This also includes some tools to generate Xcode templates.</p>
<p>Basically, the Xcode templates create a project with an external build target. So in the background all that is happening is make is being called. I found two problems with the default templates. One is that you have to use the command line to generate your templates. That isn&#8217;t really necessary since Xcode has a built in template architecture. Basically place any templates you wan to show up in the new file window in &#8220;/Developer/Library/Xcode/Project Templates&#8221;. Just make sure to create a sub folder there to create the section. I called mine AVR.</p>
<p>The second problem I had was that there is no way to upload the code to the chip. Luckily there is an easy fix. Right click on executables and select &#8220;Add: New Custom Executable&#8221;. Use /usr/bin/make as the path. Under arguments, add &#8220;flash&#8221;. This will call make, just like the target does, but it will make for flash instead of compile. Now you can select Build and Go and it will upload the program to the connected microcontroller.</p>
<p>To get going, you need to edit the makefile in the project. Select your microcontroller, for DEVICE. Input the correct value for CLOCK. I also had to add a variable for the location of the tools. I called it TOOLS</p>
<pre>DEVICE     = atmega168
CLOCK      = 8000000
PROGRAMMER = -c stk500v2 -P /dev/tty.usbmodem*
OBJECTS    = main.o
FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m

TOOLS      = /usr/local/CrossPack-AVR/bin/

AVRDUDE = $(TOOLS)avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = $(TOOLS)avr-gcc -std=c99 -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)</pre>
<p>In the PROGRAMMER line you will notice I used an asterisk (*) to select any connected programmer. I did this because the number changed on me a few times and I didn&#8217;t want to have to edit the makefile every time I plugged it in.</p>
<p>You should be good to go now. You can download <a title="Xcode AVR template" href="/wp-content/uploads/2009/10/Firmware.zip">my template</a>, but you will still need the CrossPack tools.</p>
<p>Update: <a rel="external nofollow" href="http://www.instepmusic.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.instepmusic.com/?referer=');">Jonathan</a> mentioned in the comments that you can use <a title="Engbedded Atmel AVR Fuse Calculator" href="http://www.engbedded.com/fusecalc/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.engbedded.com/fusecalc/?referer=');">http://www.engbedded.com/fusecalc/</a> to calculate the fuse bits.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidbeckblog.com/2009/10/avr-and-xcode/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
