<?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>Dana Harding &#187; Bus Pirate</title>
	<atom:link href="http://blog.oneharding.com/index.php/tag/bus-pirate/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.oneharding.com</link>
	<description></description>
	<lastBuildDate>Sun, 29 Apr 2018 17:25:34 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>Programming Arduino Pro Mini with Bus Pirate</title>
		<link>http://blog.oneharding.com/index.php/programming-arduino-pro-mini-with-bus-pirate/</link>
		<comments>http://blog.oneharding.com/index.php/programming-arduino-pro-mini-with-bus-pirate/#comments</comments>
		<pubDate>Mon, 05 Jan 2015 02:01:51 +0000</pubDate>
		<dc:creator><![CDATA[Dana]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Pro Mini 328]]></category>
		<category><![CDATA[AVR ISP]]></category>
		<category><![CDATA[Bus Pirate]]></category>

		<guid isPermaLink="false">http://blog.oneharding.com/?p=211</guid>
		<description><![CDATA[Program an Arduino Pro Mini 328 [sparkfun] board using a Bus Pirate. I tried setting up the Bus Pirate as a transparent bridge for UART to use the Arduino boot loader. I got as far as manually sending 0x30 0x20, and receiving a 0x10 0x14 &#8211; establishing communication over UART&#8230; But couldn&#8217;t get the Arduino [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><strong>Program an <a title="Arduino Pro Mini 328 - 5V/16MHz" href="https://www.sparkfun.com/products/11113">Arduino Pro Mini 328</a> [sparkfun] board using a <a title="Bus Pirate" href="https://www.sparkfun.com/products/9544">Bus Pirate</a>.</strong></p>
<div id="attachment_218" style="width: 635px" class="wp-caption aligncenter"><a href="http://blog.oneharding.com/wp-content/uploads/2015/01/IMG_1052.jpg"><img class="size-large wp-image-218" src="http://blog.oneharding.com/wp-content/uploads/2015/01/IMG_1052-1024x768.jpg" alt="Bus Pirate programming Arduino Pro Mini 328" width="625" height="468" /></a><p class="wp-caption-text">Bus Pirate programming Arduino Pro Mini 328</p></div>
<p>I tried setting up the Bus Pirate as a transparent bridge for UART to use the Arduino boot loader. I got as far as manually sending 0x30 0x20, and receiving a 0x10 0x14 &#8211; establishing communication over UART&#8230; But couldn&#8217;t get the Arduino IDE to actually upload a program to it.</p>
<p>It turns out &#8211; version depending &#8211; that avrdude can use the buspirate as an SPI programmer.<br />
<a href="http://dangerousprototypes.com/docs/Bus_Pirate_AVR_Programming">http://dangerousprototypes.com/docs/Bus_Pirate_AVR_Programming</a></p>
<h2></h2>
<p><span id="more-211"></span></p>
<h2>Wiring for SPI</h2>
<p>A bare minimum 4 connections need to be made for the communication:  MOSI, MISO, SCLK, GND.    The Arduino also needs VCC and the reset pin needs some manipulation.  I made 6 connections.</p>
<p>Pinout for my Bus Pirate: <a href="http://blog.oneharding.com/wp-content/uploads/2015/01/Bp-pin-cable-color.png"><img class="aligncenter size-full wp-image-214" src="http://blog.oneharding.com/wp-content/uploads/2015/01/Bp-pin-cable-color.png" alt="Bp-pin-cable-color" width="796" height="297" /></a><a href="http://dangerousprototypes.com/docs/Hardware_overview">http://dangerousprototypes.com/docs/Hardware_overview</a></p>
<p>&nbsp;</p>
<p>Schematic for Arduino-Pro-Mini 328 showing connections &#8211; note the locations of MSIO MOSI and SCK.  This schematic shows the actual ATMega328P pin numbers, but not the pin numbers labeled on the breakout (and used in the Arduino IDE)<br />
<a href="http://blog.oneharding.com/wp-content/uploads/2015/01/Arduino-Pro-Mini-v14.jpg"><img class="aligncenter size-full wp-image-215" src="http://blog.oneharding.com/wp-content/uploads/2015/01/Arduino-Pro-Mini-v14.jpg" alt="Arduino-Pro-Mini-v14" width="602" height="450" /></a><br />
<a href="https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Arduino-Pro-Mini-v14.pdf">https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Arduino-Pro-Mini-v14.pdf</a><br />
<a href="https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Arduino-Pro-Mini-v14.zip">https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Arduino-Pro-Mini-v14.zip</a></p>
<p>6 Connections Made:</p>
<p><a href="http://blog.oneharding.com/wp-content/uploads/2015/01/IMG_1049-connection-markup.jpg"><img class="aligncenter size-full wp-image-216" src="http://blog.oneharding.com/wp-content/uploads/2015/01/IMG_1049-connection-markup.jpg" alt="IMG_1049 connection markup" width="854" height="647" /></a></p>
<table>
<tbody>
<tr>
<td><b>Bus Pirate</b></td>
<td><b>Arduino Pro Mini 328</b></td>
</tr>
<tr>
<td>+5V (gray)</td>
<td>VCC</td>
</tr>
<tr>
<td>GND (black)</td>
<td>GND</td>
</tr>
<tr>
<td>MOSI (orange)</td>
<td>Pin 11</td>
</tr>
<tr>
<td>MISO (brown)</td>
<td>Pin 12</td>
</tr>
<tr>
<td>CLOCK (yellow)</td>
<td>Pin 13</td>
</tr>
<tr>
<td>CS (red)</td>
<td>RST</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h2>Test Bus Pirate connection</h2>
<p>$ avrdude -c buspirate</p>
<pre><code>avrdude: No AVR part has been specified, use "-p Part"

Valid parts are:
  t10  = ATtiny10        [/etc/avrdude.conf:16881]
  t9   = ATtiny9         [/etc/avrdude.conf:16837]
  t5   = ATtiny5         [/etc/avrdude.conf:16793]
  t4   = ATtiny4         [/etc/avrdude.conf:16749]
  ucr2 = 32UC3A0512      [/etc/avrdude.conf:
...
</code></pre>
<p>read the list, my part is m328p<br />
$ avrdude -c buspirate -p m328p</p>
<pre><code>avrdude: ser_open(): can't set attributes for device "/dev/ttyS0": Inappropriate ioctl for device

avrdude done.  Thank you.
</code></pre>
<p>Third try is a charm.<br />
$ avrdude -c buspirate -p m328p -P /dev/ttyUSB0</p>
<pre><code>Detecting BusPirate...
**  
**  Bus Pirate v3a
**  Firmware v5.10 (r559)  Bootloader v4.4
**  DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
**  http://dangerousprototypes.com
**
BusPirate: using BINARY mode
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done.  Thank you.
</code></pre>
<p>Success!</p>
<p>I initially had the CS wire connected to GRN &#8211; which wasn&#8217;t pulling the reset pin down. Avrdude was giving an error:</p>
<pre><code>avrdude: initialization failed, rc=-2
         Double check connections and try again, or use -F to override
         this check.
</code></pre>
<p>Connecting CS to RST fixed this. Alternatively, you can hold the reset button down during the execution of the commands.</p>
<h2></h2>
<h2>Make it work with the Arduino IDE</h2>
<p>Turned out to be deceptively simple.</p>
<p>Thanks <a href="http://www.adafruit.com/blog/2011/05/09/using-bus-pirate-with-arduino-ide/">http://www.adafruit.com/blog/2011/05/09/using-bus-pirate-with-arduino-ide/</a></p>
<p>(<a href="https://taylanayken.wordpress.com/2011/05/04/using-bus-pirate-with-arduino-ide/">https://taylanayken.wordpress.com/2011/05/04/using-bus-pirate-with-arduino-ide/</a>)</p>
<p><code>$ cd arduino-ide-location<br />
$ vi hardware/arduino/programmers.txt</code></p>
<p>Add three lines:</p>
<pre><code>
buspirate.name=The Bus Pirate
buspirate.communication=serial
buspirate.protocol=buspirate</code></pre>
<p><a href="http://blog.oneharding.com/wp-content/uploads/2015/01/Screenshot-040115-065345-PM.png"><img class="aligncenter size-full wp-image-217" src="http://blog.oneharding.com/wp-content/uploads/2015/01/Screenshot-040115-065345-PM.png" alt="Screenshot - 040115 - 06:53:45 PM" width="500" height="600" /></a></p>
<p>Load your project, select the Bus Pirate as the programmer, select the right board, serial port. Instead of &#8220;Upload&#8221;, shift-click it for &#8220;Upload using Programmer&#8221; or File-&gt;Upload using Programmer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oneharding.com/index.php/programming-arduino-pro-mini-with-bus-pirate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bus Pirate I2C / I²C interface with a DS1307 RTC</title>
		<link>http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/</link>
		<comments>http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/#comments</comments>
		<pubDate>Mon, 01 Dec 2014 00:07:14 +0000</pubDate>
		<dc:creator><![CDATA[Dana]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Bus Pirate]]></category>
		<category><![CDATA[DS1307]]></category>
		<category><![CDATA[I2C]]></category>

		<guid isPermaLink="false">http://blog.oneharding.com/?p=192</guid>
		<description><![CDATA[I picked up a Bus Pirate and cable to help with troubleshooting and future projects.     Conveniently, I am using an Adafruit Data Logging Shield for Arduino for a current project &#8211; which makes a perfect easy introduction to some of the communication with the Real Time Clock over I2C because the shield already has all [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I picked up a <a title="Bus Pirate" href="http://dangerousprototypes.com/2009/12/22/sparkfuns-bus-pirate/">Bus Pirate</a> and cable to help with troubleshooting and future projects.     Conveniently, I am using an <a title="Adafruit Data Logging Shield" href="http://www.adafruit.com/products/1141">Adafruit Data Logging Shield</a> for Arduino for a current project &#8211; which makes a perfect easy introduction to some of the communication with the Real Time Clock over I2C because the shield already has all of the supporting bits and pieces needed for the RTC.</p>

<a href='http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/img_0834/'><img width="150" height="150" src="http://blog.oneharding.com/wp-content/uploads/2014/11/IMG_0834-150x150.jpg" class="attachment-thumbnail" alt="Bus Pirate as received." /></a>
<a href='http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/img_0837/'><img width="150" height="150" src="http://blog.oneharding.com/wp-content/uploads/2014/11/IMG_0837-150x150.jpg" class="attachment-thumbnail" alt="One issue.  There - I fixed it!" /></a>

<p><span id="more-192"></span></p>
<pre><code># dmesg
[4946101.032737] usb 10-1: new full-speed USB device number 11 using uhci_hcd
[4946101.231682] usb 10-1: New USB device found, idVendor=0403, idProduct=6001
[4946101.231687] usb 10-1: New USB device strings: Mfr=1, Product=2, SerialNumber=X
[4946101.231691] usb 10-1: Product: FT232R USB UART
[4946101.231694] usb 10-1: Manufacturer: FTDI
[4946101.231696] usb 10-1: SerialNumber: AXXXXXXX
[4946101.238748] ftdi_sio 10-1:1.0: FTDI USB Serial Device converter detected
[4946101.238850] usb 10-1: Detected FT232RL
[4946101.238854] usb 10-1: Number of endpoints 2
[4946101.238857] usb 10-1: Endpoint 1 MaxPacketSize 64
[4946101.238861] usb 10-1: Endpoint 2 MaxPacketSize 64
[4946101.238864] usb 10-1: Setting MaxPacketSize 64
[4946101.240884] usb 10-1: FTDI USB Serial Device converter now attached to ttyUSB0
</code></pre>
<p>/dev/ttyUSB0 is the place to be</p>
<p><a title="Bus Pirate Self Test" href="http://dangerousprototypes.com/docs/Self-test_guide">Bus Pirate Self Test</a><br />
Jumper, Jumper, find a cable with USB Mini-B plug end.</p>
<p># screen -L /dev/ttyUSB0 115200</p>
<pre style="height: 100px;"><code>?
General					Protocol interaction
---------------------------------------------------------------------------
?	This help			(0)	List current macros
=X/|X	Converts X/reverse X		(x)	Macro x
~	Selftest			[	Start
#	Reset				]	Stop
$	Jump to bootloader		{	Start with read
&amp;/%	Delay 1 us/ms			}	Stop
a/A/@	AUXPIN (low/HI/READ)		"abc"	Send string
b	Set baudrate			123
c/C	AUX assignment (aux/CS)		0x123
d/D	Measure ADC (once/CONT.)	0b110	Send value
f	Measure frequency		r	Read
g/S	Generate PWM/Servo		/	CLK hi
h	Commandhistory			\	CLK lo
i	Versioninfo/statusinfo		^	CLK tick
l/L	Bitorder (msb/LSB)		-	DAT hi
m	Change mode			_	DAT lo
o	Set output type			.	DAT read
p/P	Pullup resistors (off/ON)	!	Bit read
s	Script engine			:	Repeat e.g. r:10
v	Show volts/states		.	Bits to read/write e.g. 0x55.2
w/W	PSU (off/ON)		/&lt;x= &gt;/	Usermacro x/assign x/list all
HiZ&gt;~
Disconnect any devices
Connect (Vpu to +5V) and (ADC to +3.3V)
Space to continue
Ctrl
AUX OK
MODE LED OK
PULLUP H OK
PULLUP L OK
VREG OK
ADC and supply
5V(4.96) OK
VPU(4.96) OK
3.3V(3.35) OK
ADC(3.28) OK
Bus high
MOSI OK
CLK OK
MISO OK
CS OK
Bus Hi-Z 0
MOSI OK
CLK OK
MISO OK
CS OK
Bus Hi-Z 1
MOSI OK
CLK OK
MISO OK
CS OK
MODE and VREG LEDs should be on!
Any key to exit
Found 0 errors.
HiZ&gt;
</code></pre>

<a href='http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/img_0839/'><img width="150" height="150" src="http://blog.oneharding.com/wp-content/uploads/2014/11/IMG_0839-150x150.jpg" class="attachment-thumbnail" alt="Powered On" /></a>
<a href='http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/img_0840/'><img width="150" height="150" src="http://blog.oneharding.com/wp-content/uploads/2014/11/IMG_0840-150x150.jpg" class="attachment-thumbnail" alt="Self Test -  &quot;MODE and VREG LEDs should be on!&quot;" /></a>

<p>&nbsp;</p>
<p>Wire up the Datalogging shield, will use the Bus Pirate to provide 5V and communicate directly with the RTC.   No Arduino involved yet.</p>
<p># screen -L /dev/ttyUSB0 115200</p>
<pre><code>HiZ&gt;m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
9. DIO
x. exit(without change)

(1)&gt;4
Set speed:
 1. ~5KHz
 2. ~50KHz
 3. ~100KHz
 4. ~400KHz

(1)&gt;3
Ready
</code></pre>
<p>The &#8216;mode&#8217; light on the Bus Pirate lights up.<br />
Bad things might happen if you have another power source and then turn on this power. (or if you have the pins wired to the wrong locations)</p>
<div id="attachment_200" style="width: 635px" class="wp-caption aligncenter"><a href="http://blog.oneharding.com/wp-content/uploads/2014/11/IMG_0846_markup.jpg"><img class="wp-image-200 size-large" src="http://blog.oneharding.com/wp-content/uploads/2014/11/IMG_0846_markup-1024x694.jpg" alt="IMG_0846_markup" width="625" height="423" /></a><p class="wp-caption-text">Four hookup points. GND label should be a bit more to the right.</p></div>
<p>Check that the RTC is there and responding, read out the current clock registers:</p>
<pre><code>I2C&gt;W
Power supplies ON
I2C&gt;(0)
 0.Macro menu
 1.7bit address search
 2.I2C sniffer
I2C&gt;(1)
Searching I2C address space. Found devices at:
0xD0(0x68 W) 0xD1(0x68 R)

I2C&gt;[0xD0 0x00[0xD1 r:8]
I2C START BIT
WRITE: 0xD0 ACK 
WRITE: 0x00 ACK 
I2C START BIT
WRITE: 0xD1 ACK 
READ: 0x38  ACK 0x29  ACK 0x22  ACK 0x01  ACK 0x30  ACK 0x11  ACK 0x14  ACK 0x00 
NACK
I2C STOP BIT </code></pre>
<p>It took a bit to figure out the read command.    The I2C protocol calls for the master to say a device&#8217;s address, followed by a read/write bit.  The DS1307 7-bit I2C address is (binary) 1101000.  Appending the read/write bit gives two addresses (11010000, 11010001) &#8211; which are the two addresses returned by the &#8216;7bit address search&#8217; macro &#8211; 0xD0 and 0xD1.</p>
<p>I WAS doing only a [0xD1 r:8] &#8211; and it was returning seemingly random values.  Turns out that the way to set the address pointer is to do a WRITE to the start address, but do another start &#8220;[&#8221; instead of specifying a value.   hence &#8220;[0xd0 0x00&#8243; &#8211; write to address 0x00, but interrupt it with &#8220;[0xd1 r:8]&#8221;  &#8211; read 8 values from 0xd1.</p>
<p>&nbsp;</p>
<p>From the <a title="DS1307 " href="http://www.mouser.com/ds/2/256/DS1307-99500.pdf">datasheet</a> [mouser.com]:<br />
<a href="http://blog.oneharding.com/wp-content/uploads/2014/11/Datasheet-Time-Registers.jpg"><img class="aligncenter wp-image-197 size-full" src="http://blog.oneharding.com/wp-content/uploads/2014/11/Datasheet-Time-Registers.jpg" alt="Datasheet-Time-Registers" width="1089" height="486" /></a>Reading the returned bytes backwards and referencing the datasheet &#8211; we can see that the RTC is set for (20)14-11-30 WeekDay#1 22:29:38, the clock is enabled (Bit7 at address 0x00h is 0), and none of the control bits are set (address 0x07h = 0x00h).   I&#8217;ve decided to call Sunday WeekDay#1, but the assignment is arbitrary.</p>
<p>The DAY register simply increments by one when the HOUR rolls over to the next day.</p>
<p>Note the year is only stored in one byte (two sets of 4 bits).  It is presumed that the actual year is &lt;value&gt; + 2000.</p>
<p>This <a title="Binary-coded_decimal" href="http://en.wikipedia.org/wiki/Binary-coded_decimal">BCD format</a> [wikipedia.org] was new to me.  It&#8217;s nice being able to (mostly) read the time straight out of the hex values.<br />
Try setting the time:</p>
<pre><code>I2C&gt;[0xd0 0x00 0x00 0x35 0x22 0x01 0x30 0x11 0x14 0x00]
I2C START BIT
WRITE: 0xD0 ACK 
WRITE: 0x00 ACK 
WRITE: 0x00 ACK 
WRITE: 0x35 ACK 
WRITE: 0x22 ACK 
WRITE: 0x01 ACK 
WRITE: 0x30 ACK 
WRITE: 0x11 ACK 
WRITE: 0x14 ACK 
WRITE: 0x00 ACK 
I2C STOP BIT

I2C&gt;[0xd0 0x00[0xd1 r:8]
I2C START BIT
WRITE: 0xD0 ACK 
WRITE: 0x00 ACK 
I2C START BIT
WRITE: 0xD1 ACK 
READ: 0x07  ACK 0x35  ACK 0x22  ACK 0x01  ACK 0x30  ACK 0x11  ACK 0x14  ACK 0x00 
NACK
I2C STOP BIT</code></pre>
<p>&nbsp;</p>
<p>Nice! This Bus Pirate is going to be a handy tool to have around.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.oneharding.com/index.php/bus-pirate-i2c-i%c2%b2c-interface-with-a-ds1307-rtc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
