<?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>welcome to the world of...</title>
	<atom:link href="http://www.smallbulb.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.smallbulb.net</link>
	<description>Looks like a small bulb used to indicate something unusual, like a malfunction.</description>
	<lastBuildDate>Wed, 09 May 2012 14:09:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>1-Wire and MSP430</title>
		<link>http://www.smallbulb.net/2012/238-1-wire-and-msp430</link>
		<comments>http://www.smallbulb.net/2012/238-1-wire-and-msp430#comments</comments>
		<pubDate>Sun, 06 May 2012 19:04:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[1-Wire]]></category>
		<category><![CDATA[bit banging]]></category>
		<category><![CDATA[ds18b20]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[mcu]]></category>
		<category><![CDATA[msp430]]></category>
		<category><![CDATA[one-wire]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[search rom]]></category>
		<category><![CDATA[temperature]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=238</guid>
		<description><![CDATA[I bought a digital thermometer DS18B20 and I wanted to connect it to my LaunchPad. DS18B20 communicates via 1-Wire protocol. I used a bit banging to emulate the protocol. CPU speed should be over 1 MHz since the protocol requires timing almost on a microsecond level. I used only two wires connection where the DS&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I bought a digital thermometer <a href="http://www.maxim-ic.com/datasheet/index.mvp/id/2812">DS18B20</a> and I wanted to connect it to my <a href="http://www.ti.com/tool/msp-exp430g2">LaunchPad</a>. DS18B20 communicates via 1-Wire protocol. I used a bit banging to emulate the protocol. CPU speed should be over 1 MHz since the protocol requires timing almost on a microsecond level.</p>
<p><span id="more-238"></span>I used only two wires connection where the DS&#8217;s VDD is connected to the ground. DS&#8217;s datasheet requires an external pull up 4.7 kohm resistor on the data line but I successfully used the MSP&#8217;s internal pull up resistor.</p>
<h2>Download</h2>
<p><a href="http://www.smallbulb.net/uploads/2012/05/msp430_onewire.tgz">Here</a>.</p>
<h2>Example of communication with DS18B20</h2>
<p>Lets connect the thermometer e.g. to pin P1.7.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;msp430.h&gt;</span>
<span style="color: #339933;">#include &quot;onewire.h&quot;</span>
<span style="color: #339933;">#include &quot;delay.h&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  onewire_t ow<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #993333;">uint8_t</span> scratchpad<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">9</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  WDTCTL <span style="color: #339933;">=</span> WDTPW <span style="color: #339933;">+</span> WDTHOLD<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Stop watchdog timer</span>
  BCSCTL1 <span style="color: #339933;">=</span> CALBC1_8MHZ<span style="color: #339933;">;</span>
  DCOCTL <span style="color: #339933;">=</span> CALDCO_8MHZ<span style="color: #339933;">;</span>
&nbsp;
  ow.<span style="color: #202020;">port_out</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1OUT<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">port_in</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1IN<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">port_ren</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1REN<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">port_dir</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1DIR<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">pin</span> <span style="color: #339933;">=</span> BIT7<span style="color: #339933;">;</span>
&nbsp;
  onewire_reset<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  onewire_write_byte<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #339933;">,</span> <span style="color: #208080;">0xcc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// skip ROM command</span>
  onewire_write_byte<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #339933;">,</span> <span style="color: #208080;">0x44</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// convert T command</span>
  onewire_line_high<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  DELAY_MS<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">800</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// at least 750 ms for the default 12-bit resolution</span>
  onewire_reset<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  onewire_write_byte<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #339933;">,</span> <span style="color: #208080;">0xcc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// skip ROM command</span>
  onewire_write_byte<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #339933;">,</span> <span style="color: #208080;">0xbe</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// read scratchpad command</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> scratchpad<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> onewire_read_byte<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  _BIS_SR<span style="color: #009900;">&#40;</span>LPM0_bits <span style="color: #339933;">+</span> GIE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Search ROM command</h2>
<p>Materials for inspiration:</p>
<ul>
<li>DS18B20 datasheet contains a flowchart but it doesn&#8217;t show very well the recursive nature of the algorithm</li>
<li><a href="http://www.maxim-ic.com/app-notes/index.mvp/id/187">1-Wire Search Algorithm</a> from Maxim</li>
</ul>
<p>Following example shows usage of <em>search ROM</em> command (0xF0). I used <em>printf()</em> and UART for debugging.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;msp430.h&gt;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdint.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &quot;onewire.h&quot;</span>
<span style="color: #339933;">#include &quot;delay.h&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/***************************************************************/</span>
&nbsp;
<span style="color: #993333;">int</span> putchar<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> c<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>c <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;">&#41;</span> putchar<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\r</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>IFG2<span style="color: #339933;">&amp;</span>UCA0TXIFG<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  UCA0TXBUF <span style="color: #339933;">=</span> c<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/***************************************************************/</span>
&nbsp;
<span style="color: #993333;">void</span> uart_setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  P1SEL <span style="color: #339933;">=</span> BIT1 <span style="color: #339933;">+</span> BIT2<span style="color: #339933;">;</span>
  P1SEL2 <span style="color: #339933;">=</span> BIT1 <span style="color: #339933;">+</span> BIT2<span style="color: #339933;">;</span>
  P1DIR <span style="color: #339933;">&amp;=</span> ~ BIT1<span style="color: #339933;">;</span>
  P1DIR <span style="color: #339933;">|=</span> BIT2<span style="color: #339933;">;</span>
  UCA0CTL1 <span style="color: #339933;">|=</span> UCSSEL_2<span style="color: #339933;">;</span>                     <span style="color: #666666; font-style: italic;">// SMCLK</span>
  UCA0BR0 <span style="color: #339933;">=</span> <span style="color: #208080;">0x41</span><span style="color: #339933;">;</span>                            <span style="color: #666666; font-style: italic;">// 8MHz 9600</span>
  UCA0BR1 <span style="color: #339933;">=</span> <span style="color: #208080;">0x03</span><span style="color: #339933;">;</span>                              <span style="color: #666666; font-style: italic;">// 8MHz 9600</span>
  UCA0MCTL <span style="color: #339933;">=</span> UCBRS0<span style="color: #339933;">;</span>                        <span style="color: #666666; font-style: italic;">// Modulation UCBRSx = 1</span>
  UCA0CTL1 <span style="color: #339933;">&amp;=</span> ~UCSWRST<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/***************************************************************/</span>
&nbsp;
<span style="color: #993333;">void</span> search<span style="color: #009900;">&#40;</span>onewire_t <span style="color: #339933;">*</span>ow<span style="color: #339933;">,</span> <span style="color: #993333;">uint8_t</span> <span style="color: #339933;">*</span>id<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> depth<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> reset<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> b1<span style="color: #339933;">,</span> b2<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">==</span> <span style="color: #0000dd;">64</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// we have all 64 bit in this search branch</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;found: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%02x&quot;</span><span style="color: #339933;">,</span> id<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>reset<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>onewire_reset<span style="color: #009900;">&#40;</span>ow<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;reset failed<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    onewire_write_byte<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> <span style="color: #208080;">0xF0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// search ROM command</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// send currently recognized bits</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> depth<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      b1 <span style="color: #339933;">=</span> onewire_read_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      b2 <span style="color: #339933;">=</span> onewire_read_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      onewire_write_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> id<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">/</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">%</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// check another bit</span>
  b1 <span style="color: #339933;">=</span> onewire_read_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  b2 <span style="color: #339933;">=</span> onewire_read_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>b1 <span style="color: #339933;">&amp;&amp;</span> b2<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// no response to search</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>b1 <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>b2<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// two devices with different bits on this position</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// check devices with this bit = 0</span>
    onewire_write_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    id<span style="color: #009900;">&#91;</span>depth <span style="color: #339933;">/</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;=</span> ~<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">%</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    search<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> id<span style="color: #339933;">,</span> depth <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// check devices with this bit = 1</span>
    id<span style="color: #009900;">&#91;</span>depth <span style="color: #339933;">/</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|=</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">%</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    search<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> id<span style="color: #339933;">,</span> depth <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// different branch, reset must be issued</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>b1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// devices have 1 on this position</span>
    onewire_write_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    id<span style="color: #009900;">&#91;</span>depth <span style="color: #339933;">/</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|=</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">%</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    search<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> id<span style="color: #339933;">,</span> depth <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>b2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// devices have 0 on this position</span>
    onewire_write_bit<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    id<span style="color: #009900;">&#91;</span>depth <span style="color: #339933;">/</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;=</span> ~<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #009900;">&#40;</span>depth <span style="color: #339933;">%</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    search<span style="color: #009900;">&#40;</span>ow<span style="color: #339933;">,</span> id<span style="color: #339933;">,</span> depth <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/***************************************************************/</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  onewire_t ow<span style="color: #339933;">;</span>
  <span style="color: #993333;">uint8_t</span> id<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 64 bits</span>
&nbsp;
  WDTCTL <span style="color: #339933;">=</span> WDTPW <span style="color: #339933;">+</span> WDTHOLD<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Stop watchdog timer</span>
  BCSCTL1 <span style="color: #339933;">=</span> CALBC1_8MHZ<span style="color: #339933;">;</span>
  DCOCTL <span style="color: #339933;">=</span> CALDCO_8MHZ<span style="color: #339933;">;</span>
  uart_setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  ow.<span style="color: #202020;">port_out</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1OUT<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">port_in</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1IN<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">port_ren</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1REN<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">port_dir</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>P1DIR<span style="color: #339933;">;</span>
  ow.<span style="color: #202020;">pin</span> <span style="color: #339933;">=</span> BIT7<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;start<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  search<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>ow<span style="color: #339933;">,</span> id<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;done<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  _BIS_SR<span style="color: #009900;">&#40;</span>LPM0_bits <span style="color: #339933;">+</span> GIE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2012/238-1-wire-and-msp430/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Emulating Raspberry Pi</title>
		<link>http://www.smallbulb.net/2012/225-emulating-raspberry-pi</link>
		<comments>http://www.smallbulb.net/2012/225-emulating-raspberry-pi#comments</comments>
		<pubDate>Sun, 04 Mar 2012 10:47:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[emulator]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[raspberry pi]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=225</guid>
		<description><![CDATA[My friend asked me if there is any possibility to try Raspberry Pi disk image in MS Windows. What a challenge! It wasn&#8217;t any challenge at all since I found almost everything prepared. First of all you need the disk image and appropriate linux kernel. Then download QEMU for Windows. Unzip the QEMU somewhere. Copy [...]]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://www.raspi.cz/">friend</a> asked me if there is any possibility to try <a href="http://www.raspberrypi.org/">Raspberry Pi</a> disk image in MS Windows. What a challenge! It wasn&#8217;t any challenge at all since I found almost everything prepared.</p>
<p><span id="more-225"></span>First of all you need the <a href="http://downloads.raspberrypi.org/images/debian/6/debian6-17-02-2012/debian6-17-02-2012.zip">disk image</a> and appropriate <a href="http://dl.dropbox.com/u/45842273/zImage_3.1.9">linux kernel</a>. Then download <a href="http://homepage3.nifty.com/takeda-toshiya/qemu/qemu-0.13.0-windows.zip">QEMU for Windows</a>. Unzip the QEMU somewhere. Copy the the disk image <em>debian6-17-02-2012.img</em> and the kernel <em>zImage_3.1.9</em> into the directory with unpacked QEMU. Then open shell/cmd and run:</p>
<pre>bin\qemu-system-arm.exe -M versatilepb -cpu arm1136-r2 -hda debian6-17-02-2012.img
                       -kernel zImage_3.1.9 -m 192 -append "root=/dev/sda2"</pre>
<p>Be patient because it could take few minutes to get even to the login phase. Login/password is pi/suse. After you log in run &#8220;startx&#8221; to enter the graphical environment. That&#8217;s it!</p>
<p>Similar procedure is possible for Linux as well. In Ubuntu you need <em>qemu-kvm-extras</em> package which contains <em>qemu-system-arm</em> executable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2012/225-emulating-raspberry-pi/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Windows 7 SDK troubleshooting</title>
		<link>http://www.smallbulb.net/2012/215-windows-7-sdk-troubleshooting</link>
		<comments>http://www.smallbulb.net/2012/215-windows-7-sdk-troubleshooting#comments</comments>
		<pubDate>Sat, 03 Mar 2012 10:49:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[cl.exe]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[mingw]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[toolchain]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=215</guid>
		<description><![CDATA[Let&#8217;s say you need to compile your C++ project under MS Windows and you need to use the Microsoft&#8217;s toolchain instead of MinGW. Buying the whole Visual Studio is not necessary. I like a simple combination gvim+scons+gcc which gives me a high amount of flexibility. I just needed to switch the gcc to the MS [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you need to compile your C++ project under MS Windows and you need to use the Microsoft&#8217;s toolchain instead of <a href="http://www.mingw.org/">MinGW</a>. Buying the whole Visual Studio is not necessary. I like a simple combination gvim+scons+gcc which gives me a high amount of flexibility. I just needed to switch the gcc to the MS compiler.</p>
<p><span id="more-215"></span>There are 2 options: <a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express">Visual C++ Express</a> or <a href="http://www.microsoft.com/download/en/details.aspx?id=18950">Windows SDK</a>. SDK is better because:</p>
<ul>
<li>contains 64-bit compiler,</li>
<li>contains debugging and profiling tools.</li>
</ul>
<p>I had two little problems with running this SDK toolchain under <strong>Windows 7</strong>. There is a broken vcvars32.bat. Running it gives an error:<strong></strong></p>
<p><strong>ERROR: Cannot determine the location of the VS Common Tools folder.</strong></p>
<p><a href="http://stackoverflow.com/a/3874987">Solution</a> is simple. Patch mentioned in the forum answer has a little flaw. Paths must end with a backslash. Then the compiler gave me another error:</p>
<p><strong>fatal error C1083: Cannot open include file: &#8216;windows.h&#8217;: No such file or directory</strong></p>
<p>Insert following line at the beginning of vcvars32.bat:</p>
<pre>@SET WindowsSdkDir=c:\Program Files\Microsoft SDKs\Windows\v7.1\</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2012/215-windows-7-sdk-troubleshooting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mass erase of MSP-EXP430FR5739</title>
		<link>http://www.smallbulb.net/2012/202-mass-erase-of-msp-exp430fr5739</link>
		<comments>http://www.smallbulb.net/2012/202-mass-erase-of-msp-exp430fr5739#comments</comments>
		<pubDate>Tue, 07 Feb 2012 21:03:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[experimenter board]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[MSP-EXP430FR5739]]></category>
		<category><![CDATA[msp430]]></category>
		<category><![CDATA[mspdebug]]></category>
		<category><![CDATA[mspgcc]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=202</guid>
		<description><![CDATA[I bought myself a new toy &#8211; MSP-EXP430FR5739 experimenter board. It didn&#8217;t stay working long because I ran into the same trouble like the guy here. Mspdebug was complaining about blow fuses. Fix was quite easy thanks to my another toy MSP-EXP430G2 LaunchPad which I luckily bought together with the experimenter board. First of all [...]]]></description>
			<content:encoded><![CDATA[<p>I bought myself a new toy &#8211; <a href="http://www.ti.com/tool/msp-exp430fr5739">MSP-EXP430FR5739 experimenter board</a>. It didn&#8217;t stay working long because I ran into the same trouble like the guy <a href="http://www.mail-archive.com/mspgcc-users@lists.sourceforge.net/msg10446.html">here</a>. Mspdebug was complaining about blow fuses. Fix was quite easy thanks to my another toy <a href="http://www.ti.com/tool/msp-exp430g2">MSP-EXP430G2 LaunchPad</a> which I luckily bought together with the experimenter board.<span id="more-202"></span></p>
<p>First of all I was confused at the beginning by no ability to load any program at all. It failed on erasing the chip. Solution: do not use programming command</p>
<pre>$ mspdebug rf2500 "prog test.elf"</pre>
<p>but use</p>
<pre>$ mspdebug rf2500 "load test.elf"</pre>
<p>because FRAM chips don&#8217;t need erasing.</p>
<p>After few loading rounds the big trouble appeared. It took me some googling to find <a href="http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/150394.aspx">this discussion</a>. This clever guy Donald created a <a href="http://dbindner.freeshell.org/msp430/fram_bsl.html">simple program</a> for LaunchPad to use BSL to mass erase the experimenter board. I tried to compile and load the program on my own but without success. The red LED always stayed on. I tried it with and without soldered crystal, both failed. Then I used Donald&#8217;s prebuilt binary with soldered crystal and it worked.</p>
<p>Now I will wait how long it will take to break again.</p>
<h4>Update 2012-02-09</h4>
<p>It didn&#8217;t take very long to jam again. Actually it took about 5 rounds of programming. My frustration was huge. After lots of another trials and failures I stumbled on a little code in mspdebug/drivers/fet.c:</p>
<pre>/* This packet seems to be necessary in order to program on the
 * MSP430FR5739 development board.
 */
if (xfer(dev, 0x30, NULL, 0, 0) &lt; 0)
  printc_dbg("fet: warning: message 0x30 failed\n");</pre>
<p>At least in my case it is not neccessary. I removed the code, experimenter board programming works fine and it does not jam any more. What a lucky shot <img src='http://www.smallbulb.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h4>Update 2012-02-12</h4>
<p>Well, card is blocked again. But this time it takes much more programming cycles then before. Better than nothing. Stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2012/202-mass-erase-of-msp-exp430fr5739/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python setup.py to DEB package</title>
		<link>http://www.smallbulb.net/2011/194-python-setup-py-to-deb-package</link>
		<comments>http://www.smallbulb.net/2011/194-python-setup-py-to-deb-package#comments</comments>
		<pubDate>Fri, 13 May 2011 09:29:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[deb]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[distutils]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rpm]]></category>
		<category><![CDATA[setup.py]]></category>
		<category><![CDATA[setuptools]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=194</guid>
		<description><![CDATA[From time to time I hit an interesting Python package which is not available in a DEB package. Setup.py/distutils/setuptools are de facto standard but the base binary distribution command set includes only RPM support. I don&#8217;t like python setup.py install. I prefer full installation/purging control via Ubuntu package system. Solution is easy. Install package python-stdeb [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I hit an interesting Python package which is not available in a DEB package. Setup.py/distutils/setuptools are de facto standard but the base binary distribution command set includes only RPM support. I don&#8217;t like <em>python setup.py install</em>. I prefer full installation/purging control via Ubuntu package system. Solution is easy.</p>
<p>Install package <strong>python-stdeb</strong> and then execute</p>
<pre>python setup.py --command-packages=stdeb.command bdist_deb</pre>
<p>And your DEB is ready!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2011/194-python-setup-py-to-deb-package/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu encrypted home</title>
		<link>http://www.smallbulb.net/2011/182-ubuntu-encrypted-home</link>
		<comments>http://www.smallbulb.net/2011/182-ubuntu-encrypted-home#comments</comments>
		<pubDate>Fri, 18 Mar 2011 18:04:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ecryptfs]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[luks]]></category>
		<category><![CDATA[notebook]]></category>
		<category><![CDATA[pam]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=182</guid>
		<description><![CDATA[I played with my new toy &#8211; HP Mini 5103 WT211ES. eCryptfs is not as enterprise as they say. It started to fail on Ubuntu 10.10. And also it is terribly slow especially for seeking. So I was looking for a better solution. I didn&#8217;t want the full disk encryption which the alternative CD offers [...]]]></description>
			<content:encoded><![CDATA[<p>I played with my new toy &#8211; <strong>HP Mini 5103 WT211ES</strong>. <strong><a href="https://launchpad.net/ecryptfs" target="_blank">eCryptfs</a></strong> is not as enterprise as they say. It started to <a href="https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/372014" target="_blank">fail</a> on <strong>Ubuntu 10.10</strong>. And also it is <strong>terribly slow</strong> especially for seeking. So I was looking for a better solution. I didn&#8217;t want the <strong>full disk encryption</strong> which the alternative CD offers during the installation because the disk is very fast and the CPU is not so fast <img src='http://www.smallbulb.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I decided to make a <strong>separate partition to host my home directory</strong> and other private data.<span id="more-182"></span></p>
<p>First I booted into the Live CD to make the disk preparations. I splitted the disk into 3 partitions:</p>
<ul>
<li>250 GB for root</li>
<li>60 GB encrypted partition</li>
<li>10 GB swap</li>
</ul>
<p>For the encryption I decided to utilize <strong>aes-ebc-plain</strong> with<strong> key size 128 bits</strong> for its <a href="http://blog.wpkg.org/2009/04/23/cipher-benchmark-for-dm-crypt-luks/" target="_blank">speed</a> (I don&#8217;t need military grade safety). Partitions formatting:</p>
<pre>mkfs.ext4 /dev/sda1
cryptsetup luksFormat -c <code>aes-ecb-null -s 128 /dev/sda2
cryptsetup luksOpen /dev/sda2 encpart
mkfs.ext4 /dev/mapper/encpart
cryptsetup luksClose encpart
</code>mkswap /dev/sda3</pre>
<p>First idea was to have the encrypted partition mounted directly to <em>/home/bobalice</em> in my final system but I wasn&#8217;t able to make the mount point owned by <em>bobalice</em>. So I created a directory <em>home/bobalice</em> on the encrypted partition and used symbolic link to &#8220;attach it&#8221;. See below. After the disk preparation I ran ordinary Ubuntu installation using the root and swap partition.</p>
<h2>Login mount</h2>
<p>Next step was to setup automatic mount of the encrypted partition. It was a kind of easy. I installed package <strong>libpam-mount</strong> and added lines to <em>/etc/security/pam_mount.conf.xml</em>:</p>
<pre>&lt;mkmountpoint enable="1" remove="true" /&gt;
&lt;volume user="bobalice" fstype="crypt"
    path="/dev/disk/by-uuid/55f028b1-3306-4de6-b420-6478ea649604"
    mountpoint="/mnt/localcrypt" /&gt;</pre>
<p>It says that only on <em>bobalice</em> login the mounting should be performed. I advice to use <strong>by-uuid</strong> partition reference because <strong>sd*</strong> labels are not constant. Now if I login as <em>bobalice</em> the partition will be mounted and ready. Next:</p>
<pre>mv /home/bobalice/.??* /enc/home/bobalice
rm -Rf /home/bobalice
usermod -d /enc/home/bobalice bobalice</pre>
<p>Now I have my home directory on the encrypted partition.</p>
<h2>GDM and initial chdir</h2>
<p>My first idea of home directory mapping was to use a symbolic link (<em>ln -sf /enc/home/bobalice /home/bobalice</em>) but it caused a little trouble with GDM. When I logged in with GDM it changed directory to the path on the encrypted mount, it followed the symlink. It is not a big deal but current working directory was different from <em>$PATH</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2011/182-ubuntu-encrypted-home/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Firefox cache and history cleanup</title>
		<link>http://www.smallbulb.net/2010/158-firefox-cache-and-history-cleanup</link>
		<comments>http://www.smallbulb.net/2010/158-firefox-cache-and-history-cleanup#comments</comments>
		<pubDate>Wed, 05 May 2010 21:25:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cleanup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=158</guid>
		<description><![CDATA[Firefox gets slower by the time. Lots of data is stored in sqlite databases. First step is cleaning cache &#8211; Menu&#62;Tools&#62;Clear Private Data &#8211; check Cache and Cookies. Other slowing stuff is the browsing history. Cleaning the whole history is not very effective way so why not remove only the oldest items? Run following in [...]]]></description>
			<content:encoded><![CDATA[<p>Firefox gets slower by the time. Lots of data is stored in sqlite databases. First step is cleaning cache &#8211; <em>Menu&gt;Tools&gt;Clear Private Data</em> &#8211; check <em>Cache</em> and <em>Cookies</em>. Other slowing stuff is the browsing history. Cleaning the whole history is not very effective way so why not remove only the oldest items?<span id="more-158"></span> Run following in the Firefox&#8217;s profile directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">MONTH</span>=<span style="color: #000000; font-weight: bold;">`</span>python <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;import time; print int(time.time()-3600*24*30)*1000000&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DELETE FROM moz_historyvisits WHERE visit_date &lt; <span style="color: #007800;">$MONTH</span>;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sqlite3 places.sqlite
<span style="color: #000000; font-weight: bold;">for</span> z <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>.sqlite; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;VACUUM;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> sqlite3 <span style="color: #ff0000;">&quot;<span style="color: #007800;">$z</span>&quot;</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This will remove items older than 30 days and maintain all the sqlite databases. Speedup is often very striking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2010/158-firefox-cache-and-history-cleanup/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSPGCC4, debugging</title>
		<link>http://www.smallbulb.net/2010/153-mspgcc4-debugging</link>
		<comments>http://www.smallbulb.net/2010/153-mspgcc4-debugging#comments</comments>
		<pubDate>Tue, 13 Apr 2010 19:34:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ddd]]></category>
		<category><![CDATA[debugger]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[msp430]]></category>
		<category><![CDATA[mspdebug]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=153</guid>
		<description><![CDATA[I recently found a forked project MSPGCC4. It is built against newer GCC and GDB. It supports multiple versions. I tried GCC 4.4.3 and GDB 7.0.1. The compilation and installation is very easy. Just run the buildgcc.sh, choose wanted versions and watch the progress. Compilation of source code for MSP430 is the same like in [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found a forked project <a href="http://mspgcc4.sourceforge.net/" target="_blank">MSPGCC4</a>. It is built against newer GCC and GDB. It supports multiple versions. I tried GCC 4.4.3 and GDB 7.0.1. The compilation and installation is very easy. Just run the buildgcc.sh, choose wanted versions and watch the progress.</p>
<p><span id="more-153"></span></p>
<p>Compilation of source code for MSP430 is the same like in the <a href="/2010/138-msp430-gcc-mspdebug">previous article</a>. Lets focus on debugging. I had troubles to make it working with the original MSPGCC project. In other words I didn&#8217;t make it working. But GDB 7.0.1 works better.</p>
<p>Mspdebug supports breakpoints only from newest versions, use git to get it (git clone git://mspdebug.git.sourceforge.net/gitroot/mspdebug). It currently supports <strong>only 1 breakpoint</strong> at a time.</p>
<p>First run the mspdebug in a stub mode:</p>
<pre>$ mspdebug -R gdb
MSPDebug version 0.7 - debugging tool for MSP430 MCUs
Copyright (C) 2009, 2010 Daniel Beer &lt;daniel@tortek.co.nz&gt;
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Trying to open interface 1 on 002
rf2500: warning: can't detach kernel driver: No data available
FET protocol version is 30000002
Configured for Spy-Bi-Wire
Set Vcc: 3000 mV
Device: MSP430F22xx
Sending magic messages for &gt;= 30000000
Bound to port 2000. Now waiting for connection...
</pre>
<p>Then run debugger. I like DDD:</p>
<pre>$ ddd --debugger msp430-gdb test.elf</pre>
<p>In the debugger console run a command to connect to the stub:</p>
<pre>(gdb) target remote :2000
0x0000e000 in _reset_vector__ ()</pre>
<p>Now you can debug at will.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2010/153-mspgcc4-debugging/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSP430, GCC, mspdebug</title>
		<link>http://www.smallbulb.net/2010/138-msp430-gcc-mspdebug</link>
		<comments>http://www.smallbulb.net/2010/138-msp430-gcc-mspdebug#comments</comments>
		<pubDate>Sat, 10 Apr 2010 21:12:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[mcu]]></category>
		<category><![CDATA[msp430]]></category>
		<category><![CDATA[mspdebug]]></category>
		<category><![CDATA[toolchain]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=138</guid>
		<description><![CDATA[This article describes brief steps to setup a Linux development tools for MSP430 MCU &#8211; compiler and programmer. MSP430 is not as well linux-supported as AVR or 8051 but fortunately there are ways to make it working. GCC The easiest way for users of Debian and derived distributions is to add following repository to /etc/apt/sources.list: [...]]]></description>
			<content:encoded><![CDATA[<p>This article describes brief steps to setup a Linux development tools for <a href="http://focus.ti.com/mcu/docs/mcuprodoverview.tsp?sectionId=95&amp;tabId=140&amp;familyId=342" target="_blank">MSP430</a> MCU &#8211; compiler and programmer. MSP430 is not as well linux-supported as AVR or 8051 but fortunately there are ways to make it working.</p>
<p><span id="more-138"></span></p>
<h2>GCC</h2>
<p>The easiest way for users of Debian and derived distributions is to add following repository to /etc/apt/sources.list:</p>
<pre>deb http://merlin.fit.vutbr.cz/FITkit/download/debian debian fitkit
</pre>
<p>Then run as root:</p>
<pre># wget http://merlin.fit.vutbr.cz/FITkit/download/debian/debkey.asc -O- | apt-key add -
# apt-get update
# apt-get install msp430-devtools
</pre>
<p>After that you will have full toolchain. Lets try to compile the following C source:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;io.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> wait<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>          <span style="color: #666666; font-style: italic;">//delay function</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">volatile</span> <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>        <span style="color: #666666; font-style: italic;">//declare i as volatile int</span>
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">32000</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//repeat 32000 times</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  WDTCTL <span style="color: #339933;">=</span> WDTPW <span style="color: #339933;">|</span> WDTHOLD<span style="color: #339933;">;</span>
&nbsp;
  P1DIR<span style="color: #339933;">=</span><span style="color: #208080;">0xFF</span><span style="color: #339933;">;</span>            <span style="color: #666666; font-style: italic;">//port 1 = output</span>
  P1OUT<span style="color: #339933;">=</span><span style="color: #208080;">0x01</span><span style="color: #339933;">;</span>            <span style="color: #666666; font-style: italic;">//set bit 0 in port 1</span>
&nbsp;
  <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">;;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>              <span style="color: #666666; font-style: italic;">//infinite loop</span>
    P1OUT<span style="color: #339933;">=</span>~P1OUT<span style="color: #339933;">;</span>        <span style="color: #666666; font-style: italic;">//invert port 1</span>
    wait<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;">//call delay function</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Compile the source and generate output suitable for programming the MCU:</p>
<pre>$ msp430-gcc -Os -mmcu=msp430x2234 -o test.elf test.c
$ msp430-objdump -DS test.elf &gt; test.lst      # assembler output
$ msp430-objcopy -O ihex test.elf test.hex
$ ls
test.c  test.elf  test.hex  test.lst</pre>
<p>It&#8217;s done!</p>
<h2>Programming</h2>
<p>For this purpose there is all-in-one tool called <a href="http://homepages.xnet.co.nz/~dlbeer/" target="_blank">mspdebug</a>. It was originaly created for <a href="http://focus.ti.com/docs/toolsw/folders/print/ez430-rf2500.html" target="_blank">EZ430-RF2500</a> but now it supports all the MSP430 programmers. I&#8217;ve tested it with the RF2500 programmer. The easiest way to program the MCU&#8217;s flash is to run the following command:</p>
<pre>$ mspdebug -R "prog test.hex"
MSPDebug version 0.6 - debugging tool for MSP430 MCUs
Copyright (C) 2009, 2010 Daniel Beer &lt;daniel@tortek.co.nz&gt;
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Trying to open interface 1 on 002
rf2500: warning: can't detach kernel driver: No data available
FET protocol version is 30000002
Configured for Spy-Bi-Wire
Set Vcc: 3000 mV
Device: MSP430F22xx
Erasing...
Writing 120 bytes to e000...
Writing  32 bytes to ffe0...</pre>
<p>It&#8217;s done!</p>
<h2>Debugging</h2>
<p><a href="/2010/153-mspgcc4-debugging">Next time&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2010/138-msp430-gcc-mspdebug/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Internet Explorer fixators &#8211; PNG, box model, &#8230;</title>
		<link>http://www.smallbulb.net/2009/109-internet-explorer-fixators-png-box-model</link>
		<comments>http://www.smallbulb.net/2009/109-internet-explorer-fixators-png-box-model#comments</comments>
		<pubDate>Thu, 10 Sep 2009 07:44:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[box model]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PNG]]></category>
		<category><![CDATA[selectors]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://www.smallbulb.net/?p=109</guid>
		<description><![CDATA[The old and painful problem with Internet Explorer is the PNG transparency. IE6 is still so wide-spread, damn. Few clever people created a JavaScript fixes for that. The best I know is iepngfix. It has a little limitation and works for IMG, background-image, &#8230; Besides the PNG transparency Internet Explorer has many other holes. Missing [...]]]></description>
			<content:encoded><![CDATA[<p>The old and painful problem with Internet Explorer is the <strong>PNG transparency</strong>. IE6 is still so wide-spread, damn. Few clever people created a JavaScript fixes for that. The best I know is <strong><a href="http://www.twinhelix.com/css/iepngfix/" target="_blank">iepngfix</a></strong>. It has a little limitation and works for IMG, background-image, &#8230;</p>
<p>Besides the PNG transparency Internet Explorer has many other holes. <strong>Missing CSS selectors, wrong box model</strong>, &#8230; I found <strong><a href="http://dean.edwards.name/IE7/" target="_blank">IE7</a></strong> script which patches most of those holes. So great! Now I can use selectors like DIV &gt; DIV or DIV + DIV everywhere. It also fixes the box model (total width = margin + border + padding + width) and min-height/min-width. It tries to fix the PNG transparency too but it is not as well tuned as the iepngfix. You should remove this path of the script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smallbulb.net/2009/109-internet-explorer-fixators-png-box-model/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

