<?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>edeca.net</title>
	<atom:link href="http://edeca.net/wp/feed/" rel="self" type="application/rss+xml" />
	<link>http://edeca.net/wp</link>
	<description>Musings of a geek</description>
	<lastBuildDate>Sat, 10 Jul 2010 11:10: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>O2 iPhone (iOS4) provisioning bug</title>
		<link>http://edeca.net/wp/2010/07/o2-iphone-ios4-provisioning-bug/</link>
		<comments>http://edeca.net/wp/2010/07/o2-iphone-ios4-provisioning-bug/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 11:10:18 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=549</guid>
		<description><![CDATA[I finally upgraded my old iPhone 3GS to iOS4, but it wasn&#8217;t a smooth process. It seems O2 have a problem with their provisioning process because, after the upgrade, all of the carrier settings had disappeared. There was no way to setup Visual Voicemail in the menu and no internet services worked when I wasn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I finally upgraded my old iPhone 3GS to iOS4, but it wasn&#8217;t a smooth process.  It seems O2 have a problem with their provisioning process because, after the upgrade, all of the carrier settings had disappeared.  There was no way to setup Visual Voicemail in the menu and no internet services worked when I wasn&#8217;t on wifi.</p>
<p>Every time the phone was plugged into the computer iTunes would say that there was an update for the carrier settings, but it never applied and the menu entries remained blank.  O2 support were only slightly helpful, taking me through the settings which appear on their website but not fixing the Visual Voicemail issues or the prompt in iTunes.</p>
<p>There are threads on the O2 site <a href="http://forum.o2.co.uk/viewtopic.php?t=47027">here</a> and <a href="http://forum.o2.co.uk/viewtopic.php?t=46661">here</a> and a useful one <a href="http://www.avforums.com/forums/iphone/1278045-visual-voice-mail-o2-setup-issues.html">on AVForums</a> which gives the fix.</p>
<p>Unfortunately the fix is to completely reset the iPhone and start from scratch.  Restoring from a backup simply brings the old (broken) settings back.  I couldn&#8217;t find a way to only synchronise contacts back to the phone, though iTunes suggests it is possible.</p>
<p>Follow these steps to repair it:</p>
<ol>
<li>erase the phone from the menu: <tt>Settings -> General -> Reset -> Erase All Content and Settings</tt></li>
<li>connect the phone to iTunes and restore iOS4</li>
<li>set the device up as a new phone, <b>not</b> from a backup!</li>
</ol>
<p>Browsing through the carrier settings menu should now show the correct values for APN (<tt>idata.o2.co.uk</tt>).  Importantly, the Visual Voicemail settings should also be in the menu.</p>
<p>Now to setup all my apps, account sand contacts from scratch..</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/07/o2-iphone-ios4-provisioning-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Net::LibNIDS 0.1 released</title>
		<link>http://edeca.net/wp/2010/06/netlibnids-0-1-released/</link>
		<comments>http://edeca.net/wp/2010/06/netlibnids-0-1-released/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 20:53:55 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=543</guid>
		<description><![CDATA[The other day I pushed a new version of Net::LibNIDS to CPAN. It interfaces with the C library libnids in order to provide TCP stream reassembly and returns the data to your Perl callback. The API for the Perl module is still nasty but a bunch of bugs have been fixed which make it quite [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I pushed a new version of <a href="http://search.cpan.org/~edeca/Net-LibNIDS/LibNIDS.pm">Net::LibNIDS</a> to CPAN.  It interfaces with the C library <a href="http://libnids.sourceforge.net/">libnids</a> in order to provide TCP stream reassembly and returns the data to your Perl callback.<br />
<span id="more-543"></span><br />
The API for the Perl module is still nasty but a bunch of bugs have been fixed which make it quite usable.  I plan on uploading some other modules in the coming months which make utilise Net::LibNIDS to do their work.</p>
<p>If you use it, make sure you use the latest version of libnids (currently v1.24) as it fixes a bunch of important bugs.  This currently isn&#8217;t in Debian/Ubuntu and the maintainer has disappeared, so compile from source for now.  Red Hat based distributions get it easy it seems, as somebody has already compiled it for RHEL4 or later.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/06/netlibnids-0-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Production music samples</title>
		<link>http://edeca.net/wp/2010/06/production-music-samples/</link>
		<comments>http://edeca.net/wp/2010/06/production-music-samples/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 21:27:57 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=538</guid>
		<description><![CDATA[Whilst looking for some music to use as jingles/beds for a charity radio project I assist I found FreeNotesMusic. From a quick listen there are some fantastic tracks, really nice composition and production. Big thanks go to Simon from the company who responded to my queries very quickly.]]></description>
			<content:encoded><![CDATA[<p>Whilst looking for some music to use as jingles/beds for a charity radio project I assist I found <a href="http://www.freenotesmusic.com/index.html">FreeNotesMusic</a>.  From a quick listen there are some fantastic tracks, really nice composition and production.</p>
<p>Big thanks go to Simon from the company who responded to my queries very quickly.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/06/production-music-samples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better than grep</title>
		<link>http://edeca.net/wp/2010/05/better-than-grep/</link>
		<comments>http://edeca.net/wp/2010/05/better-than-grep/#comments</comments>
		<pubDate>Sat, 29 May 2010 19:56:50 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=534</guid>
		<description><![CDATA[Anybody who has used command-line systems for a serious amount of time will love grep. But today I stumbled across ack, which (for many things) is better than grep and a whole lot nicer to use. The best bit? It&#8217;s pure Perl, therefore also uses real Perl regular expressions. Yes, there might be grep --perl-regexp, [...]]]></description>
			<content:encoded><![CDATA[<p>Anybody who has used command-line systems for a serious amount of time will love grep.  But today I stumbled across ack, which (for many things) is better than grep and a whole lot nicer to use.</p>
<p>The best bit?  It&#8217;s pure Perl, therefore also uses real Perl regular expressions.  Yes, there might be <tt>grep --perl-regexp</tt>, but nobody bothers compiling that in.  Plus ack has some other neat features.</p>
<p>See more at the <a href="http://betterthangrep.com/">ack website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/05/better-than-grep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cooking with gas, my first SMD board</title>
		<link>http://edeca.net/wp/2010/05/cooking-with-gas-my-first-smd-board/</link>
		<comments>http://edeca.net/wp/2010/05/cooking-with-gas-my-first-smd-board/#comments</comments>
		<pubDate>Mon, 10 May 2010 18:30:29 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=512</guid>
		<description><![CDATA[My first bunch of boards arrived back from BatchPCB and I&#8217;m really impressed.  Great printing for the silkscreen and a really professional looking product.  One of the boards I ordered was a breakout board for the SMD PIC 18F2321, the first surface mount board I have tried. The original board was designed and kindly sent [...]]]></description>
			<content:encoded><![CDATA[<p>My first bunch of boards arrived back from BatchPCB and I&#8217;m really impressed.  Great printing for the silkscreen and a really professional looking product.  One of the boards I ordered was a breakout board for the SMD PIC 18F2321, the first surface mount board I have tried.<br />
<span id="more-512"></span><br />
The original board was designed and kindly sent to me by 3v0, I tidied up the silkscreen before shipping it off to be produced.</p>
<div id="attachment_513" class="wp-caption aligncenter" style="width: 285px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-board.png"><img class="size-full wp-image-513" title="PCB0001 board" src="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-board.png" alt="" width="275" height="137" /></a><p class="wp-caption-text">Copper layers</p></div>
<p style="text-align: left;">
<div id="attachment_514" class="wp-caption aligncenter" style="width: 285px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-silkscreen.png"><img class="size-full wp-image-514" title="PCB0001 silkscreen" src="http://edeca.net/wp/wp-content/uploads/2010/05/PCB0001-silkscreen.png" alt="" width="275" height="137" /></a><p class="wp-caption-text">Silkscreen</p></div>
<p style="text-align: left;">This board uses 0803 SMD parts, but boy are they tiny.  These are some of the larger surface mount components, I definitely would not try the smaller ones.  After applying paste by hand to the board (I used <a href="http://uk.farnell.com/edsyn/cr44/solder-paste-in-syringe/dp/876768">this stuff</a>) I carefully placed the components using a <a href="http://uk.farnell.com/shesto/cl5044/seizer-straight-jaw-125mm/dp/202708">pair of tweezers</a> I bought specially.</p>
<p style="text-align: left;">Most board houses will apply a solder mask to manufactured PCBs, this is a special layer on top of the board that covers up everything except the pads.  This means a thin line of paste can be run along all the pins of the chip, there is no need to try and put an individual dot on every pad!  As the paste heats up and turns into solder the flux will evaporate and surface tension pulls the solder paste back onto each pad.</p>
<p style="text-align: left;">The original board, paste and tweezers can be seen in the image below.</p>
<p style="text-align: left;">
<div id="attachment_517" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-tools.jpg"><img class="size-medium wp-image-517" title="SMD tools" src="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-tools-300x199.jpg" alt="" width="300" height="199" /></a><p class="wp-caption-text">SMD board tools</p></div>
<p style="text-align: left;">After assembly came the fun bit, cooking time!  I kept an old frying pan specially for this, into which I placed the board.  Cooking time was no more than a few minutes, it is very visible when the paste starts to reflow and turn into molten solder.  As soon as that happened I turned off the gas hob and left it to cool.</p>
<p style="text-align: left;">
<div id="attachment_518" class="wp-caption aligncenter" style="width: 209px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/Cooking-SMD-PCB.jpg"><img class="size-medium wp-image-518" title="Cooking SMD PCB" src="http://edeca.net/wp/wp-content/uploads/2010/05/Cooking-SMD-PCB-199x300.jpg" alt="" width="199" height="300" /></a><p class="wp-caption-text">Cooking an SMD PCB!</p></div>
<p>Note that the oven thermometer really doesn&#8217;t work, it had barely reached 50°C by the time the board was finished.  A non contact IR thermometer apparently works much better and should be considered if you want to roughly follow a specific reflow profile.</p>
<p style="text-align: left;">The final result is shown below, after the header pins were hand soldered.</p>
<p style="text-align: left;">
<div id="attachment_519" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/Finished-SMD-PCB.jpg"><img class="size-medium wp-image-519" title="Finished SMD PCB" src="http://edeca.net/wp/wp-content/uploads/2010/05/Finished-SMD-PCB-300x199.jpg" alt="" width="300" height="199" /></a><p class="wp-caption-text">The finished SMD PCB</p></div>
<p style="text-align: left;">Did it work first time?  Well, mostly.  The PIC powered up, the LED blinked on and it talked to PICKit2 on the PC.  After a little examination I found that two of the pads on the chip were not properly soldered, which played havoc with some code I was writing.</p>
<p style="text-align: left;">Next time I think I would use more paste, I was quite frugal with the syringe and had to fix the two bad joints by hand.  I also probably wouldn&#8217;t design all future PCBs as SMD, populating and reflowing the board is easy but the parts are fairly expensive compared to standard &#8220;through hole&#8221; alternatives.</p>
<p style="text-align: left;">One more picture now of it in use.  This little thing really speeds up prototyping time, no need to connect a pull-up resistor, power and ICSP lines manually.  If only writing code was so easy..</p>
<p style="text-align: left;">
<div id="attachment_523" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-breakout-in-use.jpg"><img class="size-medium wp-image-523" title="SMD breakout in use" src="http://edeca.net/wp/wp-content/uploads/2010/05/SMD-breakout-in-use-300x225.jpg" alt="" width="300" height="225" /></a><p class="wp-caption-text">SMD breakout in use with a graphic LCD</p></div>
<p>For more information, watch this <a href="http://www.youtube.com/watch?v=lqYjPJJBiZo">useful video</a> on Youtube and read the excellent <a href="http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=36">SMD How To</a> from Sparkfun.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/05/cooking-with-gas-my-first-smd-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I am not a photographer</title>
		<link>http://edeca.net/wp/2010/05/i-am-not-a-photographer/</link>
		<comments>http://edeca.net/wp/2010/05/i-am-not-a-photographer/#comments</comments>
		<pubDate>Fri, 07 May 2010 17:14:09 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=484</guid>
		<description><![CDATA[During a recent conversation with another Dave he pointed me at the Facebook group No, you&#8217;re not a photographer, you just own a camera.  Whilst I don&#8217;t agree with most of the comments on there (they are generally rude and unhelpful) it does raise an interesting point: How high the bar should be set for [...]]]></description>
			<content:encoded><![CDATA[<p>During a recent conversation with <a href="http://www.davehodgkinson.com/blog">another Dave</a> he pointed me at the Facebook group <a href="http://www.facebook.com/notaphotographer">No, you&#8217;re not a photographer, you just own a  camera</a>.  Whilst I don&#8217;t agree with most of the comments on there (they are generally rude and unhelpful) it does raise an interesting point: How high the bar should be set for whether you are really a photographer  or not?<br />
<span id="more-484"></span></p>
<p>Many people, including those who charge for wedding pictures, seem to think that an entry level Canon or Nikon digital SLR with an extra lens is all that is required.  Now I&#8217;m not equipment bashing, some of them take fantastic pictures.  But that &#8220;some&#8221; is probably less than 0.5%; it is really sad just how many photos  are really just average, overprocessed snapshots.</p>
<p>To explain my point, I&#8217;ll use two pictures I have taken very recently.  Here&#8217;s the first one:</p>
<div id="attachment_486" class="wp-caption aligncenter" style="width: 209px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/IMG_0641.jpg"><img class="size-medium wp-image-486" title="Poppy" src="http://edeca.net/wp/wp-content/uploads/2010/05/IMG_0641-199x300.jpg" alt="It's just a cat" width="199" height="300" /></a><p class="wp-caption-text">Example one: A cat</p></div>
<p>Look at that amazing bokeh in the background!  Look at the way the cute little face is super sharp and the rest of her isn&#8217;t!  But really, it&#8217;s just a cat.  Unless you know the cat you probably don&#8217;t care.  This is the sort of image which becomes incredibly easy with a SLR and 15 minutes practise.  And guess what, that doesn&#8217;t make you a professional photographer.</p>
<p>Verdict?  <strong>Average</strong>.</p>
<p>Here&#8217;s the second image:</p>
<div id="attachment_490" class="wp-caption aligncenter" style="width: 310px"><a href="http://edeca.net/wp/wp-content/uploads/2010/05/Lock.jpg"><img class="size-medium wp-image-490" title="Lock" src="http://edeca.net/wp/wp-content/uploads/2010/05/Lock-300x199.jpg" alt="" width="300" height="199" /></a><p class="wp-caption-text">Example two: A bolt</p></div>
<p>Look at the awesome colours!  Feel the rustic vibe!  Oooh at the focus once again as your eyes travel around the image looking for.. well.. something interesting.  It&#8217;s not art.  It&#8217;s not good stock photography.  It&#8217;s just a rather average bolt attached to a gate that somebody happened to paint a rather hateful colour.</p>
<p>Verdict?  <strong>Incredibly average.</strong></p>
<p>Now before I am criticised for taking the fun out of photography, that isn&#8217;t my point at all.  I took the first picture because the cat is owned by two people I know, who cooed over it like proud parents. The cat hated the camera too, which was a bonus.</p>
<p>The second was an opportunistic shot as I wanted to see just how close my new lens would focus in macro mode. Quite close apparently!  I&#8217;m rather happy of how it came out as I took it  hand-held (albiet with IS), but that&#8217;s a relatively geeky photo-obsessive  thing to worry about.  Unless you are terrible with a camera, most  anything except super macro will look sharp at 800 pixels wide on a  computer screen.</p>
<p>However, neither photo required any more skill than setting the camera to Program mode and hitting a button.  Neither has a unique selling point, neither couldn&#8217;t be emulated by somebody with a minimum of teaching.  In actual fact, neither of the above images have any adjustments (exposure or otherwise) and that&#8217;s something I try to aim for.</p>
<p>I got great enjoyment from going out with my camera that day and I  learned a bit too.  But nowhere near enough to justify calling myself a  &#8220;photographer&#8221; or worse still <a href="http://www.timesonline.co.uk/tol/news/uk/article6862692.ece">charging  for wedding photography and delivering poor results</a>.  Many people  only get married once and that&#8217;s a darn good reason not to ruin their  day.</p>
<p>By all means post your photos online and take criticism, it&#8217;s the best way to improve.  Relish the fact that any digital SLR will take pictures that most compact cameras simply can&#8217;t, and that will put you above most of the rest of your friends and family.  I love looking back at my early pictures and laughing at all the silly mistakes I used to make, whilst I&#8217;m happily oblivious to the ones I am still making.</p>
<p>To wrap up slightly more positively, a link to the flickr page of a friend, <a href="http://www.flickr.com/photos/tompkinsaj/">Angela</a>.  She has been taking some lovely photos recently which deserve recognition, including a few very cute ones of some kittens.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/05/i-am-not-a-photographer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limiting command runtime in Linux</title>
		<link>http://edeca.net/wp/2010/05/limiting-command-runtime-in-linux/</link>
		<comments>http://edeca.net/wp/2010/05/limiting-command-runtime-in-linux/#comments</comments>
		<pubDate>Sun, 02 May 2010 10:55:10 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rsync]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=474</guid>
		<description><![CDATA[It is sometimes useful to limit the running time of a process, either to stop it from using up all resources or to make sure nightly cron jobs don&#8217;t continue into working hours. I needed this for rsync, to let a remote backup server slowly catch up if large amounts of data were added to [...]]]></description>
			<content:encoded><![CDATA[<p>It is sometimes useful to limit the running time of a process, either to stop it from using up all resources or to make sure nightly cron jobs don&#8217;t continue into working hours.</p>
<p>I needed this for rsync, to let a remote backup server slowly catch up if large amounts of data were added to the live server during the day.  A <a href="http://old.nabble.com/Limit-rsync-running-time-td25490601.html">useful post</a> on the rsync mailing list discusses an rsync patch but also the <tt>timeout</tt> command.</p>
<p>After installing (the Debian package is simply <tt>timeout</tt>) it is as easy as running with the number of seconds to run for:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ timeout 21600 rsync -a ...</div></div>
<p>It is also possible to specify the signal which will be sent to a program, which is useful if you do not want to simply send SIGKILL.  I used SIGHUP in the hope that rsync would have a chance to exit gracefully:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ timeout -1 21600 rsync -a ...</div></div>
<p>A full list of signals and their numeric values can be found in <tt>man 1 kill</tt>.</p>
<p>A <a href="http://johannes.jakeapp.com/blog/category/fun-with-linux/200901/bash-timeouts">wrapper script</a> is also available from Johannes Buchner.  </p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/05/limiting-command-runtime-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the hardware USART with BoostC and a PIC</title>
		<link>http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/</link>
		<comments>http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 17:08:17 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=416</guid>
		<description><![CDATA[This post looks at what is needed to get a serial connectiong working with BoostC using a PIC with a hardware USART. A later post will cover the BoostC software implementation, when I have finished figuring it out. By the end of this post there will be a PIC uC talking to Hyperterminal on the [...]]]></description>
			<content:encoded><![CDATA[<p>This post looks at what is needed to get a serial connectiong working with <a href="http://www.sourceboost.com/">BoostC</a> using a PIC with a hardware USART.  A later post will cover the BoostC software implementation, when I have finished figuring it out.</p>
<p>By the end of this post there will be a PIC uC talking to Hyperterminal on the PC using less than 50 lines of code.<br />
<span id="more-416"></span></p>
<h3>Pros &amp; cons of using the BoostC library</h3>
<p>There main advantage to using this library to implement serial communication is that it sets up all registers and control bits for you (including <tt>TRIS</tt> for the <tt>TX</tt> and <tt>RX</tt> pins).  This means limited digging around in the datasheet, you can code without worrying about the underlying hardware.</p>
<p>However it may be a disadvantage too.  The limited control over the hardware means that certain things are fixed.  For example, 8-bit transmission is the default.  It might be possible to change these by modifying the PIC registers directly but I haven&#8217;t tried this yet.  Leave a comment if you know it works!</p>
<h3>Requirements</h3>
<p>A few things are necessary to make this work.  Firstly a PIC with hardware USART support, in this post I&#8217;ll be using the PIC 18F1320 as an example.  The hardware USART is listed under &#8220;peripherals&#8221; in datasheets.</p>
<p>In order to talk to a PC we also need some form of level convertor from logic levels (+5v/0v) to <a href="http://en.wikipedia.org/wiki/RS-232">RS-232</a> (maximum voltage range +12/-12v).  I use a MAX232 breakout board that I built myself, but <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=449">this board</a> or <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=133">this board</a> from Sparkfun should work just fine.</p>
<h3>Connecting it up</h3>
<p>The purpose of this post isn&#8217;t to discuss connectivity, but briefly the PIC <tt>TX</tt> and <tt>RX</tt> pins need to be connected to the level shifter, as do +5v and GND.  The serial pins on the PIC can be found in diagrams in the datasheet.  Remember which pins they are as they are needed later.</p>
<h3>Find the right values</h3>
<p>The BoostC library is incredibly easy to use but there are a three values to work out first.  Remember the choices so they can be used in the code later.</p>
<h4>bit_time</h4>
<p>The first value is <tt>bit_time</tt>, which is the number of CPU instruction cycles per bit (note that the header file says this is used by the software USART, but code will not compile without it so it is included here for reference).</p>
<p>Take the clock speed in hz, divide by four and then divide by your desired bit rate.  I recommend starting slow (e.g. 1200 baud) and trying to faster when it works, so for an 8Mhz clock and 1200 baud we get:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">bit_time = 8000000 / 4 / 1200<br />
bit_time = 1666</div></div>
<h4>Baud rate generator mode</h4>
<p>The second thing to work out is whether we need high or low speed mode and what divisor to use.  Fortunately these are fairly simple as they are explained in the datasheet.</p>
<p>If using a <strong>slow</strong> baud rate with a <strong>fast</strong> oscillator, the datasheet recommends using the high baud rate generator.  The datasheet also suggests that it might help to reduce baud rate error.  Enabling this means using a <tt>mode</tt> of 1.  </p>
<p>For this example I used the 8Mhz internal oscillator (fairly low speed) and did not use the high speed generator, so I set <tt>mode</tt> to 0.</p>
<h4>Baud rate generator divisor</h4>
<p>Finding the divisor number is as easy as reading the datasheet to find the &#8220;SPBRG value&#8221;.  There are tables with the combinations of oscillator speed and baud rate showing the correct value.  Be careful to use the correct table for whether you plan to work with the high or low speed generator!</p>
<p>For 1200 baud at 8Mhz using the low speed generator, the value is 103.</p>
<h3>Using the code</h3>
<p>Below is example code which shows how to use the information described above.  It was adapted from the file <tt>serial_test.c</tt> which comes with BoostC.</p>
<p>For some reason the BoostC examples use the hexadecimal locations of the correct registers.  It is possible to use their names instead, e.g. <tt>TRISB</tt>/<tt>LATB</tt>/<tt>PORTB</tt> as I have below.</p>
<p>In the code below it is necessary to change 4 things:</p>
<ul>
<li>the ports and pin numbers for <tt>TX</tt> and <tt>RX</tt> (e.g. if <tt>TX</tt> is <tt>RA6</tt>, use 6)</li>
<li>the <tt>bit_time</tt> value calculated above</li>
<li>the call to <tt>uart_init</tt>, which will need the high/low speed flag and the divisor value</li>
<li>the clock frequency, if 8Mhz is not used</li>
</ul>
<h3>Code example</h3>
<div class="codecolorer-container c twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/********<br />
* &nbsp; Date: 11th April 2010<br />
* Author: David Cannings<br />
*<br />
* Example BoostC code for hardware USART on a PIC18F1320<br />
********/</span><br />
<span style="color: #339933;">#pragma CLOCK_FREQ 8000000</span><br />
<br />
<span style="color: #339933;">#include &lt;system.h&gt;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Standard 18F1320 configuration, included to pacify PICkit2</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG1H, _IESO_ON_1H &amp; _INTIO2_OSC_1H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG2L, _PWRT_ON_2L &amp; _BOR_OFF_2L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG2H, _WDT_OFF_2H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG3H, _MCLRE_ON_3H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG4L, _DEBUG_OFF_4L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG5L, _CP0_OFF_5L &amp; _CP1_OFF_5L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG5H, _CPB_OFF_5H &amp; _CPD_OFF_5H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG6L, _WRT0_OFF_6L &amp; _WRT1_OFF_6L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG6H, _WRTC_OFF_6H &amp; _WRTB_OFF_6H &amp; _WRTD_OFF_6H</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG7L, _EBTR0_OFF_7L &amp; _EBTR1_OFF_7L</span><br />
<span style="color: #339933;">#pragma DATA &nbsp;_CONFIG7H, _EBTRB_OFF_7H</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Setup the hardware USART</span><br />
<span style="color: #666666; font-style: italic;">// TODO: Set the next 6 values to the right ports and pin numbers</span><br />
<span style="color: #339933;">#define TX_PORT &nbsp; &nbsp; PORTB</span><br />
<span style="color: #339933;">#define TX_TRIS &nbsp; &nbsp; TRISB</span><br />
<span style="color: #339933;">#define TX_BIT&nbsp; &nbsp; &nbsp; 1</span><br />
<span style="color: #339933;">#define RX_PORT &nbsp; &nbsp; PORTB</span><br />
<span style="color: #339933;">#define RX_TRIS &nbsp; &nbsp; TRISB</span><br />
<span style="color: #339933;">#define RX_BIT&nbsp; &nbsp; &nbsp; 4</span><br />
<br />
<span style="color: #666666; font-style: italic;">// The following values are for 18F parts, for 16F see rs232_driver.h</span><br />
<span style="color: #339933;">#define e_SPBRG &nbsp; &nbsp; 0x0faf</span><br />
<span style="color: #339933;">#define e_RCREG &nbsp; &nbsp; 0x0fae</span><br />
<span style="color: #339933;">#define e_TXREG &nbsp; &nbsp; 0x0fad</span><br />
<span style="color: #339933;">#define e_TXSTA &nbsp; &nbsp; 0x0fac</span><br />
<span style="color: #339933;">#define e_RCSTA &nbsp; &nbsp; 0x0fab</span><br />
<span style="color: #339933;">#define e_TXIF_PIR&nbsp; 0x0f9e</span><br />
<span style="color: #339933;">#define e_RCIF_PIR&nbsp; 0x0f9e</span><br />
<span style="color: #339933;">#define e_TXIF_BIT&nbsp; 4</span><br />
<span style="color: #339933;">#define e_RCIF_BIT&nbsp; 5</span><br />
<span style="color: #339933;">#define MODE&nbsp; &nbsp; &nbsp; &nbsp; (USART_reset_wdt | USART_HW)</span><br />
<br />
<span style="color: #666666; font-style: italic;">// bit_time = FOSC / 4 / baud_rate, so 1200 baud at 8Mhz</span><br />
<span style="color: #666666; font-style: italic;">// TODO: Set bit_time here</span><br />
<span style="color: #339933;">#define bit_time 1666</span><br />
<br />
<span style="color: #339933;">#include &lt;rs232_driver.h&gt;</span><br />
<br />
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; osccon <span style="color: #339933;">=</span> <span style="color: #208080;">0x72</span><span style="color: #339933;">;</span>&nbsp; <span style="color: #666666; font-style: italic;">// 8Mhz internal oscillator</span><br />
<br />
&nbsp; &nbsp; adcon0 <span style="color: #339933;">=</span> <span style="color: #208080;">0x00</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// Disable internal ADC</span><br />
&nbsp; &nbsp; adcon1 <span style="color: #339933;">=</span> <span style="color: #208080;">0x7F</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// Set all PORTB to digital I/O</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Setup the USART, arguments are baud rate generator mode</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// and divisor</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// TODO: Set mode and divisor here</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// I chose 0 for low speed mode and 103 for 1200 baud at 8Mhz</span><br />
&nbsp; &nbsp; uart_init<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">103</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Send some text from the PIC to PC</span><br />
&nbsp; &nbsp; puts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Hello, world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// If a character is received from the PC, send it back</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>kbhit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; puts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;You pressed: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; putc<span style="color: #009900;">&#40;</span>getc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; puts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<h3>Setting up a PC client</h3>
<p>As I mentioned above the settings for serial communication are fixed by the library.  You will need to set 1200 bits per second, 8 data bits, no parity, 1 stop bit and Xon/Xoff flow control.  This is often shortened to &#8220;1200 8-N-1&#8243;.</p>
<p>If you use Hyperterminal, all settings are on the properties page for the relevant serial port.</p>
<h3>Conclusion</h3>
<p>And finally, some proof that it actually works!  If you find this post useful, or you need further help, please leave a comment below.<br />

<a href='http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/pic-hardware-usart-test/' title='PIC hardware USART test'><img width="150" height="150" src="http://edeca.net/wp/wp-content/uploads/2010/04/PIC-hardware-USART-test-150x150.jpg" class="attachment-thumbnail" alt="PIC hardware USART test" title="PIC hardware USART test" /></a>
<a href='http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/rs232-breakout-board/' title='RS232 breakout board'><img width="150" height="150" src="http://edeca.net/wp/wp-content/uploads/2010/04/RS232-breakout-board-150x150.jpg" class="attachment-thumbnail" alt="RS232 breakout board" title="RS232 breakout board" /></a>
<a href='http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/pic-rs232-screenshot/' title='PIC RS232 screenshot'><img width="150" height="150" src="http://edeca.net/wp/wp-content/uploads/2010/04/PIC-RS232-screenshot-150x150.png" class="attachment-thumbnail" alt="PIC RS232 screenshot" title="PIC RS232 screenshot" /></a>
</p>
<h3>Update</h3>
<p>Mike (K8LH) has posted a great little utility <a href="http://www.microchip.com/forums/tm.aspx?m=76411&#038;mpage=1&#038;key=&#">on the Microchip forums</a> that can help work out the correct values, if you don&#8217;t fancy digging through datasheets.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/04/using-the-hardware-usart-with-boostc-and-a-pic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obtaining DNS servers automatically on Cisco ADSL routers</title>
		<link>http://edeca.net/wp/2010/04/obtaining-dns-servers-automatically-on-cisco-adsl-routers/</link>
		<comments>http://edeca.net/wp/2010/04/obtaining-dns-servers-automatically-on-cisco-adsl-routers/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 21:00:54 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Computing]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=410</guid>
		<description><![CDATA[I noticed tonight that my Cisco 837 was using hard-coded DNS servers which were no longer valid, hence breaking my internets. In order to keep them updated automatically, I added the following to the appropriate dialer configuration (interface Dialer0 on an 8xx): ppp ipcp dns request This causes the router to request DNS server addresses [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed tonight that my Cisco 837 was using hard-coded DNS servers which were no longer valid, hence breaking my internets.  In order to keep them updated automatically, I added the following to the appropriate dialer configuration (<tt>interface Dialer0</tt> on an 8xx):</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ppp ipcp dns request</div></div>
<p>This causes the router to request DNS server addresses when the PPP session is negotiated (when it &#8220;dials up&#8221; to ADSL).</p>
<p>After reconnecting the PPP session (either reload or shutdown the interface and then bring it back) it is possible to check that DNS servers have been obtained using <tt>sh host</tt>:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">router#sh host<br />
Default domain is not set<br />
Name/address lookup uses domain service<br />
Name servers are 62.69.62.6, 62.69.62.7</div></div>
<p>If the router is running a DNS server it is possible to direct DHCP clients at the router IP instead, forcing them to use these same settings.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/04/obtaining-dns-servers-automatically-on-cisco-adsl-routers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eagle components library added</title>
		<link>http://edeca.net/wp/2010/03/eagle-components-library-added/</link>
		<comments>http://edeca.net/wp/2010/03/eagle-components-library-added/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 19:51:15 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Electronics]]></category>

		<guid isPermaLink="false">http://edeca.net/wp/?p=407</guid>
		<description><![CDATA[A very short note to say that I have (finally) published my Eagle components library on this site. Right now it doesn&#8217;t contain many parts, but I will add to it as I make more boards.]]></description>
			<content:encoded><![CDATA[<p>A very short note to say that I have (finally) published my <a href="http://edeca.net/wp/electronics/">Eagle components library</a> on this site.  Right now it doesn&#8217;t contain many parts, but I will add to it as I make more boards.</p>
]]></content:encoded>
			<wfw:commentRss>http://edeca.net/wp/2010/03/eagle-components-library-added/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
