<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Functionality of spi.read()?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1068</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:21:04 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1068" rel="self" type="application/rss+xml" />

		<item>
			<title>nplayle on "Functionality of spi.read()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1068#post-6821</link>
			<pubDate>Tue, 11 Oct 2011 13:10:37 +0000</pubDate>
			<dc:creator>nplayle</dc:creator>
			<guid isPermaLink="false">6821@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;OK thanks guys.&#60;br /&#62;
I was worried that my sending a dummy byte would eventually overwrite a register it should have. I have it working the as described and it works perfectly, so I'll leave it as is. &#60;/p&#62;
&#60;p&#62;Nick
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "Functionality of spi.read()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1068#post-6701</link>
			<pubDate>Fri, 30 Sep 2011 10:22:07 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">6701@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Check the datasheet of the device you're trying to communicate with. Generally speaking, you must always send a dummy byte like crenn said. The byte received then is the response from the device. The datasheet for the device you're communicating with will have a waveform diagram with an example of what bytes must be sent to receive data.&#60;/p&#62;
&#60;p&#62;What you've reported, however, is not a bug -- it's just the way SPI works like crenn said.&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Functionality of spi.read()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1068#post-6699</link>
			<pubDate>Fri, 30 Sep 2011 09:32:30 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">6699@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;nplayle, that's actually the way that you use SPI, if you want data back, you need to send a 'dummy' byte which isn't used for anything. Spi.read() just returns the last byte that came into the SPI data register.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Functionality of spi.read()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1068#post-6616</link>
			<pubDate>Mon, 26 Sep 2011 08:35:39 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6616@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi Nick,&#60;/p&#62;
&#60;p&#62;I'll look into this.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>nplayle on "Functionality of spi.read()?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1068#post-6569</link>
			<pubDate>Sat, 24 Sep 2011 18:10:42 +0000</pubDate>
			<dc:creator>nplayle</dc:creator>
			<guid isPermaLink="false">6569@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi all,&#60;br /&#62;
I'm a relatively new user of the maple, so forgive me if this is a simple question.&#60;/p&#62;
&#60;p&#62;I'm trying to read data via the SPI bus for an accelerometer. Writing data works as expected, but using spi.read is causing me some issues. &#60;/p&#62;
&#60;p&#62;When I send the data address out, it uses a full byte as expected. Then I use spi.read, but the chip is no longer being clocked by the spi.write command, so no data is returned to me. Since a full read cycle takes 16 clocks, the accelerometer doesnt send data until after 8 have passed. I can cheat it by writing blank data, and then the accelerometer sends data back to me, but something tells me this isnt a good way of doing it... I'm assuming it has something to do with not detecting there are unread bytes, but I'm not sure how to tell it there are.&#60;/p&#62;
&#60;p&#62;Here is the code I have&#60;br /&#62;
This works:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;      spi.write(0xE8);     
      spi.write(0x00);
      uint8 data2 = spi.read();&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This doesnt:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;spi.write(0xE8);&#38;lt;br /&#38;gt;
      uint8 data2 = spi.read();&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Thanks&#60;br /&#62;
Nick
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
