<?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>AVR Archives - Digital Me</title>
	<atom:link href="https://ba0sh1.com/tag/avr/feed/" rel="self" type="application/rss+xml" />
	<link>https://ba0sh1.com/tag/avr/</link>
	<description>Electronics, Computers at leisure time</description>
	<lastBuildDate>Tue, 31 Dec 2013 14:55:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
	<item>
		<title>JTAG adapter for Arduino Micro</title>
		<link>https://ba0sh1.com/2013/12/31/jtag-adapter-arduino-micro/</link>
					<comments>https://ba0sh1.com/2013/12/31/jtag-adapter-arduino-micro/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Tue, 31 Dec 2013 14:55:14 +0000</pubDate>
				<category><![CDATA[Diary]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[JTAG]]></category>
		<category><![CDATA[JTAGICE3]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=848</guid>

					<description><![CDATA[<p>For the holiday season I get myself an AVR JTAGICE3. Holding the new shiny emulator and a bunch of Arduino boards, what shall I do? Of course to hop onto the all-hail...</p>
<p>The post <a rel="nofollow" href="https://ba0sh1.com/2013/12/31/jtag-adapter-arduino-micro/">JTAG adapter for Arduino Micro</a> appeared first on <a rel="nofollow" href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>For the holiday season I get myself an AVR JTAGICE3. Holding the new shiny emulator and a bunch of Arduino boards, what shall I do? Of course to hop onto the all-hail Atmel Studio and ditch the toy-alike Arduino software. Reason being? Debugging Arduino code with serial console is no fun. I need my single steps, breakpoints and watches back. In fact the Arduino boards seems to be more valuable (to me) without the software. The onboard ISP connector seems to be standard and it &#8220;just works&#8221; with JTAGICE3. Well, I had this &#8220;just works&#8221; impression until I tried it on the new Arduino Micro board&#8230;<span id="more-848"></span></p>
<p>Make the story straight. The Atmel ISP connector combines SPI bus and RESET signal. SPI is used for downloading program, and RESET implements Atmel&#8217;s &#8220;debugWire&#8221; on-chip debug system. debugWire OCD is a very fancy protocol that uses only one RESET pin to debug. ATmega328p supports debugWire, and hence the ISP connector on Arduino UNO can be used for debugging. Arduino Micro uses a newer ATmega32U4 chip. Surprisingly debugWire is missing from the product datasheet, instead JTAG is listed. JTAG uses 4 I/O pins,  from Arduino Micro schematic we can see the JTAG pins (TDI/TDO/TMS/TCK) are multiplexed with analog pin A0-A3. It appears I have to sacrifice these analog pins for the JTAG interface.</p>
<figure id="attachment_854" aria-describedby="caption-attachment-854" style="width: 288px" class="wp-caption aligncenter"><img decoding="async" class="size-full wp-image-854  " title="JTAG pins on Arduino Micro" alt="JTAG pins on Arduino Micro" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/c611b-atmega32u4-jtag.png" width="288" height="196" /><figcaption id="caption-attachment-854" class="wp-caption-text">JTAG pins on Arduino Micro</figcaption></figure>
<p>JTAGICE3 comes with a 10-pin JTAG header, with the definition as follows:</p>
<figure id="attachment_855" aria-describedby="caption-attachment-855" style="width: 133px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class="size-full wp-image-855 " title="JTAG header" alt="JTAG header" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/863a1-jtag-header.png" width="133" height="135" /><figcaption id="caption-attachment-855" class="wp-caption-text">JTAGICE3 JTAG Pinout</figcaption></figure>
<p>All I need to do is to make an adapter connecting these pins:</p>
<figure id="attachment_857" aria-describedby="caption-attachment-857" style="width: 462px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/590aa-arduino-micro-jtag.png" target="_blank" rel="noopener"><img decoding="async" loading="lazy" class=" wp-image-857  " title="JTAG on Arduino Micro" alt="JTAG on Arduino Micro" src="https://www.ba0sh1.com/wp-content/uploads/2013/12/Arduino-Micro-JTAG-1024x423.png" width="462" height="191" /></a><figcaption id="caption-attachment-857" class="wp-caption-text">JTAG on Arduino Micro</figcaption></figure>
<p>The actual construction is done on a perf board. I made it Arduino &#8220;Shield&#8221; type so they can be simply stacked together.</p>
<figure id="attachment_859" aria-describedby="caption-attachment-859" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/756bb-arduino-micro-jtag-shield.png"><img decoding="async" loading="lazy" class="size-full wp-image-859" alt="Arduino Micro JTAG Shield" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/756bb-arduino-micro-jtag-shield.png" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2013/12/756bb-arduino-micro-jtag-shield.png 600w, https://ba0sh1.com/wp-content/uploads/2013/12/756bb-arduino-micro-jtag-shield-300x225.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-859" class="wp-caption-text">Arduino Micro JTAG Shield</figcaption></figure>
<p>I admit it looks quite dangerous when stacked up <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f62e.png" alt="😮" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<figure id="attachment_861" aria-describedby="caption-attachment-861" style="width: 600px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/74d25-arduino-micro-with-jtag.png" target="_blank" rel="noopener"><img decoding="async" loading="lazy" class="size-full wp-image-861 " alt="JTAG connected" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/74d25-arduino-micro-with-jtag.png" width="600" height="450" srcset="https://ba0sh1.com/wp-content/uploads/2013/12/74d25-arduino-micro-with-jtag.png 600w, https://ba0sh1.com/wp-content/uploads/2013/12/74d25-arduino-micro-with-jtag-300x225.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption id="caption-attachment-861" class="wp-caption-text">JTAG connected</figcaption></figure>
<p>I hook up JTAGICE3 and choose JTAG interface in Atmel Studio. And no surprise. Murphy gets me everytime! &#8220;[ERROR] No JTAG devices detected.&#8221; is the only reply I get. I Scratch my head several hours then to realize how stupid I were. Since the pins PF4-PF7 have been used as analog inputs for Arduino, how can JTAG establish connection with these pins! And the resolution is simple: connect using ISP header and enable the JTAGEN fuse bit. Now I feel the usefulness of ISP connector.</p>
<figure id="attachment_862" aria-describedby="caption-attachment-862" style="width: 560px" class="wp-caption aligncenter"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/2863d-enable-jtagen.png" target="_blank" rel="noopener"><img decoding="async" loading="lazy" class=" wp-image-862  " alt="Enable JTAGEN Fuse" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/12/2863d-enable-jtagen.png" width="560" height="480" srcset="https://ba0sh1.com/wp-content/uploads/2013/12/2863d-enable-jtagen.png 700w, https://ba0sh1.com/wp-content/uploads/2013/12/2863d-enable-jtagen-300x257.png 300w" sizes="(max-width: 560px) 100vw, 560px" /></a><figcaption id="caption-attachment-862" class="wp-caption-text">Enable JTAGEN Fuse</figcaption></figure>
<p>I can finally talk to ATmega32U4 using JTAG and do some debugging. The coming year will be interesting <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://ba0sh1.com/2013/12/31/jtag-adapter-arduino-micro/">JTAG adapter for Arduino Micro</a> appeared first on <a rel="nofollow" href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2013/12/31/jtag-adapter-arduino-micro/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Tutorial: 3.3V hacking for Arduino Nano</title>
		<link>https://ba0sh1.com/2013/03/30/tutorial-3-3v-hacking-for-arduino-nano/</link>
					<comments>https://ba0sh1.com/2013/03/30/tutorial-3-3v-hacking-for-arduino-nano/#comments</comments>
		
		<dc:creator><![CDATA[Baoshi]]></dc:creator>
		<pubDate>Sat, 30 Mar 2013 12:17:24 +0000</pubDate>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[AVR]]></category>
		<guid isPermaLink="false">https://www.ba0sh1.com/?p=591</guid>

					<description><![CDATA[<p>Hey I&#8217;m writing my first tutorial 🙂 During my recent OLED testing I wrote the software using Arduino Pro Mini 3.3 &#8211; the only Arduino board with 3.3V I/O (Lilipad may be the...</p>
<p>The post <a rel="nofollow" href="https://ba0sh1.com/2013/03/30/tutorial-3-3v-hacking-for-arduino-nano/">Tutorial: 3.3V hacking for Arduino Nano</a> appeared first on <a rel="nofollow" href="https://ba0sh1.com">Digital Me</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hey I&#8217;m writing my first tutorial <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>During my recent<a title="Poorman’s OLED test jig" href="https://www.ba0sh1.com/oled-test-jig/"> OLED testing</a> I wrote the software using Arduino Pro Mini 3.3 &#8211; the only Arduino board with 3.3V I/O (Lilipad may be the other one but not breadboard friendly). Originally I was using the SPI interface and everything works fine. But when I&#8217;m trying to test the I2C interface I suddenly realize the I2C lines are not on the breadboard pins! Instead they are on top of the board and I have to use jumper wires to connect them, not as neat as I would like ;p<span id="more-591"></span></p>
<p>Looking into my inventory I found an Arduino Nano with all the necessary pins. But it uses 5V I/O only. So how to modify an Arduino Nano to 3.3V<!--more-->?  Adafruit already has a <a href="http://learn.adafruit.com/arduino-tips-tricks-and-techniques/3-3v-conversion" target="_blank" rel="noopener">tutorial</a> about it. But judging from the photos the modification is on a Uno. Uno uses different USB chip from Nano&#8217;s FT232RL, and hence we need some more steps.</p>
<p>So here is what we need:</p>
<ol>
<li>Arduino Nano (of course)</li>
<li>A 3.3V regulator in SOT-223 package. Please note the official Nano design uses UA78M05 regulator, which has a different pin configuration than the popular LM1117-3.3. The one I found compatible is Micrel&#8217;s <a href="http://www.micrel.com/_PDF/mic37100.pdf" target="_blank" rel="noopener">MIC37100-3.3WS</a>, Digikey link <a href="http://www.digikey.com/product-detail/en/MIC37100-3.3WS/576-1163-ND/771632" target="_blank" rel="noopener">here</a>.</li>
<li>An Atmel ISP programmer, such as AVR JTAGICE mkII, or usbasp, or even a second Arduino as ISP.</li>
<li>A good magnifier!</li>
</ol>
<p>Schematic below is the official Arduino Nano design with necessary modifications marked in red:</p>
<p style="text-align:center;"><a class="thumbnail" href="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/03/8fd06-arduinonano-3.3.png" target="_blank" rel="noopener"><img decoding="async" loading="lazy" class="aligncenter size-large wp-image-594" alt="ArduinoNano 3.3" src="https://www.ba0sh1.com/wp-content/uploads/2013/03/ArduinoNano-3.3-1024x662.png" width="770" height="497" /></a></p>
<ol>
<li>Replace the original voltage regulator.</li>
<li>Locate D1 from the board, cut the trace at cathode side and connect cathode to VIN of the regulator. Alternatively you can also remove D1 completely, but by doing so the Nano board is unable to be powered from USB, You&#8217;ll need to provide your own source voltage from Pin 1.</li>
<li>Cut the trace at FT232RL pin 4 (VCCIO), and connect pin 4 to pin 17 (3V3OUT). This enables FT232RL to use 3.3V logic.</li>
<li>Cut the trace at FT232RL pin 20 (VCC) and connect pin 20 to D1 anode (VUSB).</li>
</ol>
<p>I would suggest to trace your board carefully before doing step 3 and 4. In my case the board is a Chinese <del>enhanced</del> modified version and all the power pins are connected by vias under FT232RL. So I had to desolder the whole chip to break the links. Just to share my modified board:</p>
<figure id="attachment_595" aria-describedby="caption-attachment-595" style="width: 640px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class="thumbnail size-full wp-image-595" alt="Modified Arduino Nano" src="http://blog.ba0sh1.com/wordpress/wp-content/uploads/2013/03/6c9d0-arduinonano-conversion.jpg" width="640" height="480" srcset="https://ba0sh1.com/wp-content/uploads/2013/03/6c9d0-arduinonano-conversion.jpg 640w, https://ba0sh1.com/wp-content/uploads/2013/03/6c9d0-arduinonano-conversion-300x225.jpg 300w" sizes="(max-width: 640px) 100vw, 640px" /><figcaption id="caption-attachment-595" class="wp-caption-text">Modified Arduino Nano</figcaption></figure>
<p>Till here the hardware modification is done.</p>
<p>However, if you carefully read the 660-page ATmega328 datasheet (which you should), at the bottom of first page:</p>
<figure id="attachment_597" aria-describedby="caption-attachment-597" style="width: 770px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class="thumbnail size-large wp-image-597" alt="ATmega328p clock" src="https://www.ba0sh1.com/wp-content/uploads/2013/03/ATmega328p-Clock-1024x699.png" width="770" height="525" /><figcaption id="caption-attachment-597" class="wp-caption-text">ATmega328p clock</figcaption></figure>
<p>Yes the chip is only specified at 10MHz with 3.3V supply. So unless you want to overclock your 3.3V Arduino at 16MHz, you should try to reduce the clock frequency.</p>
<p>Although the simplest way to modify clock frequency is to replace the 16MHz crystal with a 8MHz one, I&#8217;m out of luck because my board is using a tiny resonate instead of standard HC-49S crystal.</p>
<p>So the other way is modify the Arduino bootloader, configure CLKPR register to divide the clock by 2. To do this, follow the steps below:</p>
<ol>
<li><span style="line-height:13px;">Go to &#8220;c:arduino-1.0.3hardwarearduinobootloaders&#8221;, make a copy of &#8220;atmega&#8221; folder, I name my new folder &#8220;atmegad2&#8221;</span></li>
<li>Inside &#8220;atmegad2&#8221;, edit &#8220;ATmegaBOOT_168.c&#8221;, look for the main() function and add the following<br />
[code language=&#8221;cpp&#8221;]<br />
uint16_t w;</p>
<p>#ifdef CLKDIV2<br />
// Disable interrupts<br />
ch = SREG;<br />
cli();<br />
// Enable clock change<br />
CLKPR = _BV(CLKPCE);<br />
// Change clock division<br />
CLKPR = 0x1;<br />
// Enough time for new clock to be stable?<br />
asm volatile(<br />
  &quot;nop nt&quot;<br />
  &quot;nop nt&quot;<br />
  &quot;nop nt&quot;<br />
  &quot;nop nt&quot;<br />
);<br />
SREG = ch;<br />
#endif</p>
<p>#ifdef WATCHDOG_MODS<br />
&#8230;<br />
[/code]</li>
<li>Edit &#8220;Makefile&#8221;, add a new build target (I added right below &#8220;atmega328_pro8_isp: isp&#8221;)<br />
[code]<br />
atmega328_pro16div2: TARGET = atmega328_pro_16MHz_Div2<br />
atmega328_pro16div2: MCU_TARGET = atmega328p<br />
atmega328_pro16div2: CFLAGS += &#8216;-DMAX_TIME_COUNT=F_CPU&gt;&gt;4&#8217; &#8216;-DNUM_LED_FLASHES=1&#8217; -DBAUD_RATE=57600 -DDOUBLE_SPEED -DCLKDIV2<br />
atmega328_pro16div2: AVR_FREQ = 8000000L<br />
atmega328_pro16div2: LDSECTION  = &#8211;section-start=.text=0x7800<br />
atmega328_pro16div2: $(PROGRAM)_atmega328_pro_16MHzDiv2.hex<br />
[/code]</li>
<li>Create a batch file &#8220;env.bat&#8221;, content below. This is to set correct building environment for the boot loader. You do not need a separate installation of WinAVR as the current version of WinAVR has some definition problem with Arduino bootloader source. The WinAVR within Arduino distribution is just fine.<br />
[code]<br />
set path=c:arduino-1.0.3hardwaretoolsavrbin;c:Appsarduino-1.0.3hardwaretoolsavrutilsbin;%PATH%<br />
[/code]</li>
<li>Open a command prompt, cd into &#8220;c:arduino-1.0.3hardwarearduinobootloadersatmegad2&#8221;, execute the follow:<br />
[code]<br />
c:arduino-1.0.3hardwarearduinobootloadersatmegad2&gt;env.bat<br />
&#8230;&#8230;..<br />
c:arduino-1.0.3hardwarearduinobootloadersatmegad2&gt;make atmega328_pro16div2<br />
avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF_CPU=8000000L   &#8216;-DMAX_TIME_COUNT=F_CPU&gt;&gt;4&#8217; &#8216;-DNUM_LED_FLASHES=1&#8217; -DBAUD_RATE=57600 -DDOUBLE_SPEED -DCLKDIV2   -c -o ATmegaBOOT_168.o ATmegaBOOT_168.c<br />
avr-gcc -g -Wall -O2 -mmcu=atmega328p -DF_CPU=8000000L   &#8216;-DMAX_TIME_COUNT=F_CPU&gt;&gt;4&#8217; &#8216;-DNUM_LED_FLASHES=1&#8217; -DBAUD_RATE=57600 -DDOUBLE_SPEED -DCLKDIV2 -Wl,&#8211;section-start=.text=0x7800 -o ATmegaBOOT_168_atmega328_pro_16MHzDiv2.elf ATmegaBOOT_168.o<br />
avr-objcopy -j .text -j .data -O ihex ATmegaBOOT_168_atmega328_pro_16MHzDiv2.elf ATmegaBOOT_168_atmega328_pro_16MHzDiv2.hex<br />
rm ATmegaBOOT_168_atmega328_pro_16MHzDiv2.elf ATmegaBOOT_168.o</p>
<p>c:arduino-1.0.3hardwarearduinobootloadersatmegad2&gt;<br />
[/code]</p>
<p>When the building ended, you should have &#8220;ATmegaBOOT_168_atmega328_pro_16MHzDiv2.hex&#8221; in the folder.</li>
<li>Use you ISP programmer, burn  &#8220;ATmegaBOOT_168_atmega328_pro_16MHzDiv2.hex&#8221; into ATmega328p chip. You do not need to reprogram the fuses but just in case you need, the fuse settings are:<br />
[code]<br />
HFUSE = DA<br />
LFUSE = FF<br />
EFUSE = 05<br />
[/code]</li>
</ol>
<p>Now you can use your Arduino Nano just as an Arduino Pro Mini 3.3/8Mhz, write some blink LED program to test the new clock. Have fun with 3.3V devices!</p>
<p>The post <a rel="nofollow" href="https://ba0sh1.com/2013/03/30/tutorial-3-3v-hacking-for-arduino-nano/">Tutorial: 3.3V hacking for Arduino Nano</a> appeared first on <a rel="nofollow" href="https://ba0sh1.com">Digital Me</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ba0sh1.com/2013/03/30/tutorial-3-3v-hacking-for-arduino-nano/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
	</channel>
</rss>
