<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" 
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
	<channel>
<title>Serial Solutions</title><link>http://www.esawdust.com/blog/index.html</link><description>Dealing with serial ports and data</description><dc:language>en</dc:language><dc:creator>landon@360vl.com</dc:creator><dc:rights>Copyright 2007-2009 Landon Cox</dc:rights><dc:date>2009-01-30T05:09:00-07:00</dc:date><admin:generatorAgent rdf:resource="http://www.realmacsoftware.com/" />
<admin:errorReportsTo rdf:resource="mailto:landon@360vl.com" /><sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
<lastBuildDate>Sat, 12 Apr 2008 13:17:39 -0600</lastBuildDate><item><title>Build a Hardened&#x2c; USB to Serial Cable With CAT5</title><dc:creator>landon@360vl.com</dc:creator><category>Serial</category><category>USB</category><dc:date>2009-01-30T05:09:00-07:00</dc:date><link>http://www.esawdust.com/blog/blog/serial/files/Hardened-USB-Extension-Cable.html#unique-entry-id-4</link><guid isPermaLink="true">http://www.esawdust.com/blog/blog/serial/files/Hardened-USB-Extension-Cable.html#unique-entry-id-4</guid><content:encoded><![CDATA[<strong><em>Synopsis</em></strong> - This project uses CAT5 cable and a USB to serial converter to cheaply extend USB cables long distances.  Using a Sparkfun USB to serial breakout board and an RJ-45 breakout, it&rsquo;s simple to create a cheap USB to serial extension using CAT5 cable.   Since there is no enclosure available for a USB to serial device, I also present a whacky way to harden the unit so it can be installed in a rugged environment.<br /><br /><img class="imageStyle" alt="USB-Serial-Extension22" src="http://www.esawdust.com/blog/serial/files/usb-serial-extension22.jpg" width="183" height="137"/><br /><br />Read on for how to build a rugged USB to TTL serial extension to your microcontroller.]]></content:encoded></item><item><title>SD/MMC SPI Initialization Waveforms</title><dc:creator>landon@360vl.com</dc:creator><category>Serial</category><category>LogicPort</category><dc:date>2008-12-21T17:21:28-07:00</dc:date><link>http://www.esawdust.com/blog/blog/serial/files/SPI_SD_MMC_ATMega128_AVR.html#unique-entry-id-3</link><guid isPermaLink="true">http://www.esawdust.com/blog/blog/serial/files/SPI_SD_MMC_ATMega128_AVR.html#unique-entry-id-3</guid><content:encoded><![CDATA[<strong><em>Synopsis</em></strong><em>:  This is an example AVR ATMega128 interaction with an SD/MMC Flash memory card using the SPI protocol.  Until you&rsquo;ve worked with the SPI protocol for reading or writing an SD/MMC card, it can be a little hard to visualize how SPI works with flash memory devices.  It doesn&rsquo;t show the code but focuses on the waveforms and timing on the wire for the 4 SPI signals - MOSI, MISO, SCK, and SS.   It also shows how the protocol behaves in a real test with a Lexar or Kodak SD Card and what kind of timing is realistic.<br /><br />[update 9/21/09: somewhere along the line the web tool I use stopped generating the correct link for the enlarged waveform shots.  My apologies - it&rsquo;s corrected now - can click on images to expand.]</em><br /><br />These images clearly show how an AVR ATMega128 talks to an SD card through the SPI interface.   The SPI physical level consists of 4 pins - MOSI (master out slave in), MISO (master in slave out), SS (slave select) and SCK (clock).   These screen shots will show the state of the various SPI lines for slave select, MOSI, MISO, and Clock during the initialization sequence of an SD card. <br /><br />This initialization sequence below demonstrates how to wake up an SD card and put it into SPI mode (vs an SD native mode API.)<br /><br />This timing is taken from a working AVR ATMega128 to SD (Lexar 128MB) flash card initialization, so it&rsquo;s known to work well.  The clock needs to be relatively slow - 125kHz - SPI on the AVR ATMega128 can go up to 4MHz.   Start slow and when you get something working, then you can try higher speeds.  I&rsquo;ve tried faster clocks and have not been able to get all SD&rsquo;s to respond to the initialization sequence.  I&rsquo;ve seen code examples which do initialization at a very slow clock, then after the SD is in SPI mode (after this initialization sequence), they crank the clock speed up.   I haven&rsquo;t done enough experimentation to say what to crank it up to in order to achieve consistent results with various SD cards.<br /><br />If you click on the screen shot you&rsquo;ll get a full size image of the waveforms.  These are wide images so either you may need to scroll horizontally to see it all or you will need to expand your browser window very wide to see it all<br /><br /><strong><u>Waking Up an SD Card with SCK and CMD0</u></strong><br /><br /><a href="http://sawdust.see-do.org/images/SPI/MMC-SPI-Initialization-Sequence.jpg" rel="lightbox" title="SD SPI First Portion of Initialization"><img class="imageStyle" alt="MMC-SPI-Initialization-Sequence" src="http://www.esawdust.com/blog/serial/files/mmc-spi-initialization-sequence.jpg" width="480" height="122"/></a><br />Click the images to enlarge - the SPI waveforms will be clearly seen in the large images.<br /><br />The screen shot above shows the first stage of waking up an SD card.  To start the sequence:<br /><br />1.) <strong>Send 80 cycles of clock</strong> (usually 10 pokes of the AVR SPI register will clock these to the line as you see leading up to the sequence), <br />2.) <strong>Send a 0x40 (CMD0 | 0x40) </strong>per the specs for communicating to the SD card that it should switch to SPI mode),   At the point you start this sequence, you&rsquo;re technically in SD native mode, so you have to have a valid checksum byte (0x95.)  After converting to SPI mode, the checksum byte may be ignored (or optionally enforced.)<br />3.) <strong>Send 4 bytes of 0x00.  </strong>bytes are ignored but must be there as a placeholder<br />4.) <strong>Send checksum of 0x95.</strong><br /><br />Send 8-16 SCK cycles (2 spi() calls) and you should see a response from your SD Card.   See the MISO line go from high to low about 16 clocks after the initial sequence was sent.  The response you&rsquo;re looking for after a CMD0 command is, 0x01.  See the MISO data decode above.  Unless you get that response, you can&rsquo;t continue with the wake up sequence.<br /><br />Notice that besides the clock (80 cycles) leading up to the main initialization sequence, the first action is the Slave Select line is pulled low because select is active low.   If you have no other SPI devices on the bus, you can take it low and leave it there.  It will stay low for the duration of the initialization sequence or at any  other time you are reading or writing the device.  For my tests, I take it low, go through initialization and leave it low for reads and writes because I have no other SPI devices on the bus.<br /><br /><strong><u>CMD1, Continued Initialization of the SD Card</u></strong><br /><br />That simple sequence is the first part.  You then follow it up with an SD CMD1 command  (0x01 | 0x40 as it looks on the line.)  The same protocol transpires as you clock it in.  In the screenshot below, I&rsquo;ve show the CMD1 sequence on the tail of the CMD0 sequence:<br /><br /><a href="http://sawdust.see-do.org/images/SPI/MMC-SPI-Initialization-Sequence-CMD01.jpg" rel="lightbox" title="SPI SD/MMC CMD1 sequence - Busy Response"><img class="imageStyle" alt="MMC-SPI-Initialization-Sequence-CMD01-Response" src="http://www.esawdust.com/blog/serial/files/mmc-spi-initialization-sequence-cmd01-response.jpg" width="480" height="110"/></a><br /><br />Notice the 0x41 to lead off the 6 byte packet...that&rsquo;s the CMD1 | 0x40 byte.  Also, notice the response on the MISO line starting 8 cycles after the checksum (0x95) is sent, it&rsquo;s 0x01.  This is a &ldquo;busy&rdquo; indication from the SD card.  Continuing sending CMD1 while you continue to get a busy response.  When the response is finally not busy, the card is initialized in SPI mode and ready for the other types of SD SPI bus commands.<br /><br />For the SD Cards I was using, I only had to send two CMD1 commands before the SD Card was ready.  Here&rsquo;s the final CMD1 command:<br /><br /><a href="http://sawdust.see-do.org/images/SPI/MMC-SPI-Initialization-Sequence-CMD01-Response.jpg" rel="lightbox" title="SD CMD1 Response Not Busy"><img class="imageStyle" alt="MMC-SPI-Initialization-Sequence-CMD01" src="http://www.esawdust.com/blog/serial/files/mmc-spi-initialization-sequence-cmd01.jpg" width="480" height="111"/></a><br /><br /><br />For completeness, the sequence below shows a portion of the 80 clock cycles that are required to lead into the first CMD0 command.<br /><a href="http://sawdust.see-do.org/images/SPI/SD-MMC-SPI-Initialization-Waveforms.jpg" rel="lightbox" title="SPI 80 cycles lead in initialization"><img class="imageStyle" alt="SD-MMC-SPI-Initialization-Waveforms" src="http://www.esawdust.com/blog/serial/files/sd-mmc-spi-initialization-waveforms.jpg" width="480" height="116"/></a><br /><br /><strong><u>Best SPI to SD/MMC Protocol Tutorial On the Web</u></strong><br /><br />I learned a lot about SPI and SD/MMC communication from this article on the web:  <a href="http://elm-chan.org/docs/mmc/mmc_e.html" rel="external" title="Great SPI SD/MMC Tutorial">http://elm-chan.org/docs/mmc/mmc_e.html</a><br /><br />While there is some visualization of a SPI waveform in the elm-chan tutorial, the SPI SD waveforms in the screenshots above are pulled from an actual SPI SD communication session and I think can fill in some visual and conceptual gaps if you&rsquo;re not too familiar with the sequences.<br /><br /><strong><u>About This Configuration</u></strong><br /><br />To capture these waveforms, I used the <a href="http://www.pctestinstruments.com/" rel="external" title="LogicPort USB logic analyzer">LogicPort 34 Channel Logic Analyzer.</a><br /><br />I used a <a href="http://www.esawdust.com/etavr.html" rel="external" title="ET-AVR Futurlec ATMega128">ET-AVR Stamp </a>connected to an <a href="http://www.esawdust.com/etavrdevbrd.html" rel="external" title="ET-AVR Development Board">ET-AVR Development board</a> and <a href="http://www.esawdust.com/components/etmmcmini.html" rel="external" title="MMC/SD Mini-board">MMC/SD mini-board</a> for SD testing.  I used Kodak 2GB SD Card, Lexar 128MB SD Card, and Lexar 2GB SD Card to watch variations in behavior.   The LogicPort analyzer leads are on the left side.  The ET-AVR dev board&rsquo;s nice because you can run jumpers using, say, male to male connections and there&rsquo;s another row of connectors for every pin on the AVR that can be used for logic tracing.  It&rsquo;s just a very convenient board to work on with the exception of needing to <a href="http://sawdust.see-do.org/avr/files/AVRJTAGICE-Connector.html" rel="self" title="JTAGICE mkii squid to IDE socket connection">use a squid to attach the JTAGICE mkii</a> if you also want to use SPI.<br /><br /><a href="http://www.esawdust.com/product/bkob-sd-mmc/" rel="self" title="ET-AVR SD/MMC Module"><img class="imageStyle" alt="DSCF1553" src="http://www.esawdust.com/blog/serial/files/dscf1553.jpg" width="480" height="360"/></a><br /><br /><br /><a href="http://www.esawdust.com/product/dvbd-et-avrbd/" rel="self" title="ET-AVR Development Board"><img class="imageStyle" alt="ET-AVR-DevBoard-WithSDMMC" src="http://www.esawdust.com/blog/serial/files/et-avr-devboard-withsdmmc.jpg" width="480" height="359"/></a><br /><br /><strong><u>Summary</u></strong><br /><br />These images help show how to communicate to an SD card from a SPI-capable microcontroller such as the ATMega128.  The most important phase of this is initializing the SD Card for SPI protocol operation as the above images demonstrate.<br /><br />Reading and writing to the card after this much has been accomplished is a much easier task.<br />]]></content:encoded></item><item><title>HOWTO - LogicPort Trigger on Serial Character</title><dc:creator>landon@360vl.com</dc:creator><category>Serial</category><category>LogicPort</category><category>Propeller</category><dc:date>2008-07-17T16:35:32-06:00</dc:date><link>http://www.esawdust.com/blog/blog/serial/files/LogicPortSerialTrigger.html#unique-entry-id-2</link><guid isPermaLink="true">http://www.esawdust.com/blog/blog/serial/files/LogicPortSerialTrigger.html#unique-entry-id-2</guid><content:encoded><![CDATA[Synopsis: I was working on a serial multiplexor based on a <a href="http://www.parallax.com/Default.aspx?tabid=407" rel="external">Propeller</a> development board.  Because there could be many serial streams coming into or out of the mux, I needed to be able to analyze the serial stream in real-time to debug it and verify and validate it was working as I expected.<br /><br />I bought a <a href="http://www.pctestinstruments.com" rel="external">LogicPort 34 channel logic analyzer </a>to help me do the job but figuring out the best way to get it to trigger on an incoming or outgoing serial character took me a little time to figure out.  This is a quick tutorial on how I did it.<br /><br /><img class="imageStyle" alt="DSCF0611" src="http://www.esawdust.com/blog/serial/files/page10_blog_entry2_1.jpg" width="365" height="274"/>]]></content:encoded></item><item><title>Ruby Serial Port</title><dc:creator>landon@360vl.com</dc:creator><category>Serial</category><category>Ruby</category><dc:date>2008-04-12T13:10:59-06:00</dc:date><link>http://www.esawdust.com/blog/blog/serial/files/RubySerialPort.html#unique-entry-id-1</link><guid isPermaLink="true">http://www.esawdust.com/blog/blog/serial/files/RubySerialPort.html#unique-entry-id-1</guid><content:encoded><![CDATA[Ruby is a great programming language for many purposes.  Whenever possible, I look for excuses to use it rather than any other choice out there.  However, it's weak when it comes to device support for embedded projects.  That said, one package that helps bridge the gap is the Ruby-serialport  - it provides the classes needed to access a system's serial port from Ruby. ]]></content:encoded></item><item><title>HOWTO - Serial to IP Conversion</title><dc:creator>landon@360vl.com</dc:creator><category>Lantronix</category><dc:date>2007-06-14T09:02:54-06:00</dc:date><link>http://www.esawdust.com/blog/blog/serial/files/LANTronixSerial2IP.html#unique-entry-id-0</link><guid isPermaLink="true">http://www.esawdust.com/blog/blog/serial/files/LANTronixSerial2IP.html#unique-entry-id-0</guid><content:encoded><![CDATA[There's often a need to get a serial microcontroller or sensor device (GPS, range sensor, etc) that have serial connections onto an IP network.  In order to do that though you have to convert serial to an IP data stream.  Fortunately, there's a lot of highly integrated, functional modules that can help.<br /><br />I built a simple and cheap serial to TCP/IP converter using a <a href="http://www.lantronix.com/device-networking/embedded-device-servers/xport-direct.html" rel="external" title="LANTronix XPort Direct">LANtronix XPort Direct module.</a>  Parts cost of this is about $40. Here's a picture of the prototype:<br /><br /><img class="imageStyle" alt="Pasted Graphic 2" src="http://www.esawdust.com/blog/serial/files/page10_blog_entry0_1.jpg" width="347" height="259"/>]]></content:encoded></item></channel>
</rss>