<?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>MachineGrid &#187; serial parser</title>
	<atom:link href="http://www.machinegrid.com/tag/serial-parser/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.machinegrid.com</link>
	<description>robots at work</description>
	<lastBuildDate>Mon, 19 Jul 2010 01:59:06 +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>A Simple Serial Parser Using A State Machine</title>
		<link>http://www.machinegrid.com/2009/01/a-simple-serial-parser-using-a-state-machine/</link>
		<comments>http://www.machinegrid.com/2009/01/a-simple-serial-parser-using-a-state-machine/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 20:07:52 +0000</pubDate>
		<dc:creator>bluehash</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[serial parser]]></category>
		<category><![CDATA[state machine]]></category>

		<guid isPermaLink="false">http://www.blog.machinegrid.com/?p=294</guid>
		<description><![CDATA[This note illustrates how to decode or parse incoming serial data with an example. Transmitting one byte serially to a microcontroller is simple.The easiest way to do this is to interrupt the controller when a byte arrives on the receive pin. There is no need to parse or separate data as whatever comes in, is [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><!-- New window script from http://blog.ginchen.de/en/2008/12/20/links-xhtml-konform-in-neuem-fenster-oeffnen/ --><script src="http://www.machinegrid.com/machinepress/jscripts/externalLinks.js" type="text/javascript"></script>This note illustrates how to decode or parse incoming serial data with an example. Transmitting one byte serially to a microcontroller is simple.The easiest way to do this is to interrupt the controller when a byte arrives on the receive pin. There is no need to parse or separate data as whatever comes in, is assigned to a variable. But what if there is more than one byte that needs to be received.How would you go about separating all the bytes and put them into their respective variables?</p>
<p>The example illustrated here is to parse direction,steering angle and speed sent from a PC to a microcontroller, in this case a Microchip PIC16F876A. Parsing in this example is based on the idea of a state machine. If you need to know more about state machines, the following link may be helpful:<br />
Microchip forums : <a rel="external" href="http://forum.microchip.com/tm.aspx?m=163425">Most efficient way to &#8220;decode&#8221; serial data?</a><br />
Most of the code used here is based on feature article by Glen Worstell on a &#8220;Ham Radio Repeater Locator&#8221; using a Garmin GPSMAP 295.<br />
Links : <a rel="external" href="http://www.circuitcellar.com/library/print/0804/Worstell_169/Worstell-169.pdf">Here</a><br />
code : <a href="ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2004/169">Here</a> (ftp).</p>
<p>In this example, my PC transmits a serial string &#8220;$122133200&#8243; where :<br />
$ : Start of String(SOS)<br />
122: Direction(Note 1)<br />
133: Steering Angle<br />
200: Speed</p>
<p>In my microcontroller the incoming string is compared byte by byte with a parser string &#8220;$dddtttsss&#8221; using a state machine where :<br />
$ : Start of String(SOS)<br />
ddd: Direction<br />
ttt: Steering Angle<br />
sss: Speed<br />
The State Machine:<br />
<img src="http://www.machinegrid.com/machinepress/wp-content/uploads/media/images/serial_parser/state_machine.jpg" alt="" width="414" height="327" /></p>
<p>State 0: The state machine does nothing until a &#8220;$&#8221; or Start of String(SOS) is received.<br />
State 1: &#8220;$&#8221; received.If not goto State 0.<br />
State 2: The parser knows that the next(second) byte coming in has to be a Direction parameter, because of the &#8220;d&#8221; in the parser string If a number comes in, it is stored. If anyhing anything other than a number is received, it is discarded and the machine returns to State 0. This continues for 2 more bytes.<br />
State 3: The fifth byte is the steering angle, represented by a &#8220;t&#8221; in the parser string.Ths same for the sixth and seventh bytes. State 4: The eighth byte is the Speed, known by the &#8220;s&#8221; in the parser.</p>
<p>The state machine is reset or restarted after the tenth byte.<br />
If you declare the direction,steering angle and Speed as an int8 or a char, the final value for each parameter would be :<br />
for direction:<br />
direction = direction * 10 + received byte.</p>
<p>Direction = 0*10 + 1 = 1<br />
Direction = 1*10 + 2 = 12<br />
Direction = 12*10 + 2= 122<br />
<img src="http://www.machinegrid.com/machinepress/wp-content/uploads/media/images/serial_parser/parse.jpg" alt="" width="666" height="572" /><br />
The following source code is for the Micrchip PIC16F876A, written in CCS.<br />
Code : <a href="http://www.machinegrid.com/machinepress/wp-content/uploads/media/code/serial_parser/pic_parser.c">Here</a></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.machinegrid.com/2009/01/a-simple-serial-parser-using-a-state-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
