<?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>YourITronics &#187; SPI</title>
	<atom:link href="http://www.youritronics.com/tag/spi/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.youritronics.com</link>
	<description>DIY, Electronics, IT, Gadgets</description>
	<lastBuildDate>Fri, 16 Dec 2011 19:22:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Logic Analyzer on PicKit2</title>
		<link>http://www.youritronics.com/logic-analyzer-on-pickit2/</link>
		<comments>http://www.youritronics.com/logic-analyzer-on-pickit2/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 19:03:36 +0000</pubDate>
		<dc:creator>Florin</dc:creator>
				<category><![CDATA[DIY]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[logic analyzer]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[Pic32]]></category>
		<category><![CDATA[PicKit2]]></category>
		<category><![CDATA[SPI]]></category>

		<guid isPermaLink="false">http://www.youritronics.com/?p=3502</guid>
		<description><![CDATA[Pretty much every time I tried to work with some sort of digital interface I run into some kind of trouble where a logic analyzer would have saved me hours of blind debugging and posting to various forums. Same thing happened when I decided to try the TMP121 temperature sensor from TI which has an [...]]]></description>
			<content:encoded><![CDATA[<p>Pretty much every time I tried to work with some sort of digital interface I run into some kind of trouble where a logic analyzer would have saved me hours of <em>blind debugging</em> and posting to various forums. Same thing happened when I decided to try the <strong>TMP121 temperature sensor</strong> from TI which has an SPI interface. It was the first time I worked with SPI on a pic32 and as expected nothing worked for the first try. The code for setting the SPI interface and reading from it seemed correct, I took it from the &#8220;32 bit peripheral lib user guide&#8221; from Microchip.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #008080; font-style: italic;">//configure SPI</span>
OpenSPI1<span style="color: #008000;">&#40;</span>SPI_MODE16_ON <span style="color: #008000;">|</span> SPI_SMP_ON <span style="color: #008000;">|</span> SPI_CKE_ON <span style="color: #008000;">|</span> MASTER_ENABLE_ON <span style="color: #008000;">|</span> CLK_POL_ACTIVE_HIGH <span style="color: #008000;">|</span> SEC_PRESCAL_8_1 <span style="color: #008000;">|</span> PRI_PRESCAL_16_1, SPI_ENABLE<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//start reading T1</span>
mPORTEClearBits<span style="color: #008000;">&#40;</span>BIT_0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		<span style="color: #008080; font-style: italic;">// pull CS low to prepare for reading</span>
<span style="color: #0600FF; font-weight: bold;">while</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>DataRdySPI1<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
T1 <span style="color: #008000;">=</span> ReadSPI1<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		<span style="color: #008080; font-style: italic;">// read 16 bit word</span>
mPORTESetBits<span style="color: #008000;">&#40;</span>BIT_0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		<span style="color: #008080; font-style: italic;">// pull CS high</span></pre></div></div>

<p>So what else could be wrong ? Well at this point it could be a faulty sensor or incorrect use of the SPI interface maybe I wasn&#8217;t generating the clock correctly or maybe some wiring issue. This is the point where you need to have a logic analyzer. While I don&#8217;t have a proper logic analyzer I do have a PicKit2 and it can emulate a 3 channel, modest logic analyzer. I hooked up one of channels to the SCK pin and I noticed I wasn&#8217;t getting any clock signal. But why isn&#8217;t the clock being generated ? The answer came from the Microchip forums, the guys there pointed out that in order to generate the clock signal you have to issue a dummy write. By issuing a dummy write you start generating the clock and you can do the reading. So I added a new line to the code and tried again:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//configure SPI</span>
OpenSPI1<span style="color: #008000;">&#40;</span>SPI_MODE16_ON <span style="color: #008000;">|</span> SPI_SMP_ON <span style="color: #008000;">|</span> SPI_CKE_ON <span style="color: #008000;">|</span> MASTER_ENABLE_ON <span style="color: #008000;">|</span> CLK_POL_ACTIVE_HIGH <span style="color: #008000;">|</span> SEC_PRESCAL_8_1 <span style="color: #008000;">|</span> PRI_PRESCAL_16_1, SPI_ENABLE<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">//start reading T1</span>
mPORTEClearBits<span style="color: #008000;">&#40;</span>BIT_0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		<span style="color: #008080; font-style: italic;">// pull CS low to prepare for reading</span>
SPI1BUF <span style="color: #008000;">=</span> 0x00<span style="color: #008000;">;</span>			<span style="color: #008080; font-style: italic;">// this sends a 0x00 just to make the clock toggle in order to read</span>
<span style="color: #0600FF; font-weight: bold;">while</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>DataRdySPI1<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
T1 <span style="color: #008000;">=</span> ReadSPI1<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		<span style="color: #008080; font-style: italic;">// read 16 bit word</span>
mPORTESetBits<span style="color: #008000;">&#40;</span>BIT_0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>		<span style="color: #008080; font-style: italic;">// pull CS high</span></pre></div></div>

<p>This time I also connected a second channel from the logic analyzer to the SDI pin on the pic32 (data in) and it worked <img src='http://www.youritronics.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  , here is the capture:<img class="alignnone size-full wp-image-3509" title="Capture of TMP121 output data on SPI bus" src="http://www.youritronics.com/wp-content/uploads/2010/12/Capture-of-TMP121-output-data-1.png" alt="Capture of TMP121 output data on SPI bus" width="649" height="439" /></p>
<p>As you can see on channel 2 there are 16 clock cycles corresponding to the 16 bit word sent by the TMP121 and on channel 3 connected to SDI(data in on pic32) is the actual binary temperature. If we analyze the data on Ch3, for every falling SCK edge we get <strong>0001101010100000</strong> we can discard the first bit cause its the sign bit (0 = positive , 1 = negative) and plug the rest of the bits in a calculator just to check the data.</p>
<div id="attachment_3511" class="wp-caption alignnone" style="width: 266px"><a href="http://www.youritronics.com/wp-content/uploads/2010/12/binary-data-in-windows-calculator-1.png"><img class="size-full wp-image-3511 " title="binary data in windows calculator" src="http://www.youritronics.com/wp-content/uploads/2010/12/binary-data-in-windows-calculator-1.png" alt="binary data in windows calculator" width="256" height="235" /></a><p class="wp-caption-text">note: windows calc discards the leading 0&#39;s</p></div>
<p>Next we convert to decimal and we get a value of <strong>6816.</strong></p>
<p><a href="http://www.youritronics.com/wp-content/uploads/2010/12/decimal-data-in-windows-calculator-1.png"><img class="alignnone size-full wp-image-3512" title="decimal data in windows calculator" src="http://www.youritronics.com/wp-content/uploads/2010/12/decimal-data-in-windows-calculator-1.png" alt="decimal data in windows calculator" width="254" height="235" /></a></p>
<p>6816 is not quite the number that we were looking for, but remember the data is represented in two&#8217;s complement so we have to <strong>divide it by 256</strong> to get the actual temperature in degrees C.</p>
<p><a href="http://www.youritronics.com/wp-content/uploads/2010/12/actual-temperature-in-windows-calculator-1.png"><img class="alignnone size-full wp-image-3513" title="actual temperature in windows calculator" src="http://www.youritronics.com/wp-content/uploads/2010/12/actual-temperature-in-windows-calculator-1.png" alt="actual temperature in windows calculator" width="256" height="257" /></a></p>
<p>The result after division by 256 is <strong>26.625 degrees C</strong>. This was the room temperature at the time of this test. From here on everything is simple, I know I&#8217;m getting the right data out of the sensor its just a matter of processing and using it. And here is a picture of the PCB I made for the TMP121 in SOT23-6 package. Probably one of the smallest PCB I made at home, 30&#215;10 mm.</p>
<p><a href="http://www.youritronics.com/wp-content/uploads/2010/12/TMP121-temperature-sensor-PCB.jpg"><img class="alignnone size-medium wp-image-3515" title="TMP121 temperature sensor PCB" src="http://www.youritronics.com/wp-content/uploads/2010/12/TMP121-temperature-sensor-PCB-300x225.jpg" alt="TMP121 temperature sensor PCB" width="300" height="225" /></a></p>
<p>Now I&#8217;m seriously thinking about getting the <a href="http://dangerousprototypes.com/category/logic-analyzer/">Logic Sniffer</a> from Dangerous Prototypes, it&#8217;s a must have.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youritronics.com/logic-analyzer-on-pickit2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>LIS3LV02DQ Triple Axis Accelerometer</title>
		<link>http://www.youritronics.com/lis3lv02dq-triple-axis-accelerometer/</link>
		<comments>http://www.youritronics.com/lis3lv02dq-triple-axis-accelerometer/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 18:39:32 +0000</pubDate>
		<dc:creator>Florin</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Microcontroller]]></category>
		<category><![CDATA[Accelerometer]]></category>
		<category><![CDATA[LIS3LV02DQ]]></category>
		<category><![CDATA[Sensor]]></category>
		<category><![CDATA[SPI]]></category>

		<guid isPermaLink="false">http://www.youritronics.com/?p=1318</guid>
		<description><![CDATA[The project it&#8217;s based on a nice little 3-axis accelerometer from STMicroelectronics with a SPI bus, which makes it handy for interfacing in microcontroller style applications.  This device could be interfaced with an AVR, but the author chose to interface it with the Arduino, since it&#8217;s pretty easy to get up and running in that [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youritronics.com/wp-content/uploads/2008/07/lis3lv02dq-triple-axis-accelerometer.jpg"><img class="alignnone size-medium wp-image-1319" title="lis3lv02dq-triple-axis-accelerometer" src="http://www.youritronics.com/wp-content/uploads/2008/07/lis3lv02dq-triple-axis-accelerometer-300x225.jpg" alt="LIS3LV02DQ Triple Axis Accelerometer" width="300" height="225" /></a></p>
<p>The project it&#8217;s based on a nice little 3-axis accelerometer from STMicroelectronics with a <a href="http://en.wikipedia.org/wiki/Serial_Peripheral_Interface">SPI</a> bus, which makes it handy for interfacing in microcontroller style applications.  This device could be interfaced with an AVR, but the author chose to interface it with the Arduino, since it&#8217;s pretty easy to get up and running in that environment.</p>
<p><strong>LIS3LV02DQ Triple Axis Accelerometer:</strong> <a href="http://www.nearfuturelaboratory.com/2006/09/22/arduino-and-the-lis3lv02dq-triple-axis-accelerometer/">[Link]</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youritronics.com/lis3lv02dq-triple-axis-accelerometer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with VMUSIC2</title>
		<link>http://www.youritronics.com/getting-started-with-vmusic2/</link>
		<comments>http://www.youritronics.com/getting-started-with-vmusic2/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 17:02:12 +0000</pubDate>
		<dc:creator>Florin</dc:creator>
				<category><![CDATA[Audio]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[SPI]]></category>
		<category><![CDATA[UART]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[VMUSIC]]></category>

		<guid isPermaLink="false">http://www.youritronics.com/?p=1288</guid>
		<description><![CDATA[Remember when i told you a few words about a new revolutionary USB Module named VMUSIC2 ? The VMUSIC2 is a complete MP3 player module from FTDI, Inc. which makes it easy to integrate MP3 functionality in to your next microcontroller project. It has two interfaces: SPI or UART (serial) This instructable will cover getting [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youritronics.com/wp-content/uploads/2008/07/getting-started-with-vmusic2.jpg"><img class="alignnone size-medium wp-image-1289" title="getting-started-with-vmusic2" src="http://www.youritronics.com/wp-content/uploads/2008/07/getting-started-with-vmusic2-300x225.jpg" alt="Getting started with VMUSIC2" width="300" height="225" /></a></p>
<p>Remember when i told you a few words about a new revolutionary USB Module named <a title="Vmusic2 USB" href="http://www.youritronics.com/vmusic-module-easily-add-usb-flash-drive-interface/">VMUSIC2</a> ? The VMUSIC2 is a complete MP3 player module from FTDI, Inc. which makes it easy to integrate MP3 functionality in to your next microcontroller project. It has two interfaces: SPI or UART (serial)</p>
<blockquote><p>This instructable will cover getting connected and controlling your VMUSIC2 module from hyperterminal. I recommend starting out this way because it will allow you to get familiar with the commands and get a feel for how it works before connecting it to your microcontroller. I will follow up with another instructable on controlling it from a microcontroller.</p></blockquote>
<p><strong>Getting started with VMUSIC2:</strong> <a href="http://www.instructables.com/id/Getting-started-with-VMUSIC2/">[Link]</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youritronics.com/getting-started-with-vmusic2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

