<?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: Working with SPI</title>
		<link>http://forums.leaflabs.com/topic.php?id=539</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:25:02 +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=539" rel="self" type="application/rss+xml" />

		<item>
			<title>DerFreD on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-4872</link>
			<pubDate>Sun, 29 May 2011 12:29:03 +0000</pubDate>
			<dc:creator>DerFreD</dc:creator>
			<guid isPermaLink="false">4872@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks a lot for your help. Tuesday I'm gonna find out whether it works.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-4871</link>
			<pubDate>Sun, 29 May 2011 10:09:55 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">4871@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Although I haven't used the new SPI library, I took a look at the code. I believe the transmit function does return the byte sent by the slave during the last transmission. So it is full duplex mode. You do need to manually set NSS to low and high before and after transmissions.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>DerFreD on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-4869</link>
			<pubDate>Sat, 28 May 2011 18:48:11 +0000</pubDate>
			<dc:creator>DerFreD</dc:creator>
			<guid isPermaLink="false">4869@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Some quick questions on SPI I cannont figure out myself:&#60;/p&#62;
&#60;p&#62;I am encouraged to use spi.transmit, read and write. Does transmit return the byte that was send by the slave while the master was clocking the transmitted byte (full-duplex)? Looking at HardwareSPI.c made me suspect otherwise but I need full-duplex mode.&#60;/p&#62;
&#60;p&#62;Do I have to &#34;manually&#34; set NSS low before and back high after transmission?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jarek on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2877</link>
			<pubDate>Tue, 30 Nov 2010 00:23:15 +0000</pubDate>
			<dc:creator>jarek</dc:creator>
			<guid isPermaLink="false">2877@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks to everyone who helped, my project is now well under way =]
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2864</link>
			<pubDate>Mon, 29 Nov 2010 19:13:53 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">2864@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer -- thank you and noted; we'll make sure this is fixed in the new docs.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2849</link>
			<pubDate>Fri, 26 Nov 2010 20:15:32 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">2849@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;That's a case of you need to use a loop and Spi.send(data);. The ADXL is such a device, I'd be happy if the code used the array passed to it and feed the return data into that. I've thought about fiddling with it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2846</link>
			<pubDate>Fri, 26 Nov 2010 19:21:11 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2846@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;It should be mentioned that the Spi.send(data, size) returns the last byte recieved, and Spi.send(data) returns a single byte after the data has been pushed though. &#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Glerk! I didn't read the SPI stuff carefully enough.&#60;br /&#62;
I can't think which device it is right now (and I'm going to bed), but I think I have a datasheet somewhere for a device which wouldn't work. It sends more than one byte back when the master sends a byte.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2842</link>
			<pubDate>Fri, 26 Nov 2010 19:00:15 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">2842@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;It should be mentioned that the Spi.send(data, size) returns the last byte recieved, and Spi.send(data) returns a single byte after the data has been pushed though.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2835</link>
			<pubDate>Fri, 26 Nov 2010 04:15:53 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2835@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;There is actually 2 ways Spi.send works.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;LeafLabs - The SPI documentation at &#60;a href=&#34;http://leaflabs.com/docs/maple/spi/#functions&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/maple/spi/#functions&#60;/a&#62; is missing the single parameter send function mentioned by crenn.&#60;/p&#62;
&#60;p&#62;Also, the existing documentation is a tiny bit broken&#60;br /&#62;
&#60;code&#62;Spi.send(data, size()&#60;/code&#62;&#60;br /&#62;
should be&#60;br /&#62;
&#60;code&#62;Spi.send(data, size)&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Also, their are no SPI 'receive' functions documented.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2828</link>
			<pubDate>Thu, 25 Nov 2010 19:27:16 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">2828@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;There is actually 2 ways Spi.send works. You can either send an array of bytes (more efficient) or send a single byte at a time, you're trying to send a single byte while using the multiple byte function. All you need is Spi.send(0x13); where 0x13 is the value you want to send.&#60;/p&#62;
&#60;p&#62;Another thing I'm curious about is the CS signal, you only set it back to HIGH briefly before you're about to send data, why not back to high after you send data?&#60;/p&#62;
&#60;p&#62;Last thing, to remove the warning, change int n, to unsigned int n.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2826</link>
			<pubDate>Thu, 25 Nov 2010 09:53:09 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2826@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I've only had a quick look, but&#60;/p&#62;
&#60;p&#62;The spi.send() function is declared as&#60;br /&#62;
uint8 send(uint8*, uint32)&#60;br /&#62;
the first parameter, &#60;code&#62;uint8*&#60;/code&#62;, is the &#60;em&#62;memory address&#60;/em&#62; of some values, and not the  values themselves.&#60;/p&#62;
&#60;p&#62;So, to make your code work, change&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;Spi.send(address, sizeof(byte));
Spi.send(data, sizeof(byte));&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;to&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;Spi.send(&#38;amp;address, sizeof(byte));
Spi.send(&#38;amp;data, sizeof(byte));&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The '&#60;code&#62;&#38;amp;&#60;/code&#62;' operator takes the address of a memory location, in this case variables called &#60;code&#62;data&#60;/code&#62; and &#60;code&#62;address&#60;/code&#62;, which matches send()'s definition.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jarek on "Working with SPI"</title>
			<link>http://forums.leaflabs.com/topic.php?id=539#post-2821</link>
			<pubDate>Wed, 24 Nov 2010 21:08:21 +0000</pubDate>
			<dc:creator>jarek</dc:creator>
			<guid isPermaLink="false">2821@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm trying to port an Arduino sketch to Maple because I need the 18MHz SPI Speed. After changing over all the SPI calls, I'm getting tons of errors, and can't figure any of them out. Can someone lend a hand?&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;HardwareSPI Spi(1);

const int initTable[24] =  {0x30,0x08,0x00,0x00,0x30,0x08,0x00,0x00,0x80,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x40};
const byte tableHi[] = {0x07,0x07,0x07,0x06,0x06,0x05,0x05,0x05,0x05,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const byte tableLo[] = {0xF1,0x80,0x13,0xAD,0x4D,0xF3,0x9D,0x4D,0x00,0xB8,0x75,0x35,0xF8,0xBF,0x89,0x56,0x26,0xF9,0xCE,0xA6,0x7F,0x5C,0x3A,0x1A,0xFB,0xDF,0xC4,0xAB,0x93,0x7C,0x67,0x52,0x3F,0x2D,0x1C,0x0C,0xFD,0xEF,0xE2,0xD2,0xC9,0xBD,0xB3,0xA9,0x9F,0x96,0x8E,0x86,0x7E,0x77,0x70,0x6A,0x64,0x5E,0x59,0x54};
                                                     //These tables were taken from &#60;a href=&#34;http://www.freewebs.com/the_bott/NotesTableNTSC.txt&#34; rel=&#34;nofollow&#34;&#62;http://www.freewebs.com/the_bott/NotesTableNTSC.txt&#60;/a&#62;
                                                     //tableHi is the top 3 bits for $4003, tableLo is the bottom 8 bits for $4002
int latchPin = 8;

volatile boolean state = false;                      //switch to make sure I write values at the right time

void writeData(){                                    //routine to switch state while NES is BRKing
  state=true;                                        //switch state
}

void sendAddrData(byte address, byte data){    //routine to send address and data along to &#38;#39;245s when interrupt is thrown
  state = false;                                     //set switch
  while (state!=true);                               //wait for interrupt to throw switch back
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);
  Spi.send(address, sizeof(byte));
  Spi.send(data, sizeof(byte));
}

void setup() {
  Spi.begin(SPI_18MHZ, MSBFIRST, 0);
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);
  Spi.send(0x15, sizeof(byte));
  Spi.send(0x1F, sizeof(byte));
  attachInterrupt(0, writeData, RISING);             //begin interrupt function on pin 21, calls writeData on falling edge
  for (byte n = 0; n &#38;lt; 0x18; n++) sendAddrData(n,initTable[(int)n]);
}

void loop() {                                        //main loop
  sendAddrData(0x15, 0x1F);                          //Turn on all channels
  sendAddrData(0x00, 0xBF);                          //Turn square wave to max volume, 50% duty, etc
  sendAddrData(0x01, 0x08);                          //Negate sweeps
  for(int n; n &#38;lt; sizeof(tableHi)/sizeof(int); n++)
  {
    sendAddrData(0x02, tableLo[n]);                  //increment through the note table posted above, low bits
    sendAddrData(0x03, tableHi[n]);                  //increment through the note table posted above, high bits
    sendAddrData(0x1F, 0x00);                        //end write, NES does its thing now
    delay(125);                                      //note duration
  }
  sendAddrData(0x15, 0x00);                          //silence all channels
  sendAddrData(0x1F, 0x00);                          //end write
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Errors:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp: In function &#38;#39;void sendAddrData(byte, byte)&#38;#39;:
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:26: error: invalid conversion from &#38;#39;byte&#38;#39; to &#38;#39;uint8*&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:26: error:   initializing argument 1 of &#38;#39;uint8 HardwareSPI::send(uint8*, uint32)&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:27: error: invalid conversion from &#38;#39;byte&#38;#39; to &#38;#39;uint8*&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:27: error:   initializing argument 1 of &#38;#39;uint8 HardwareSPI::send(uint8*, uint32)&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp: In function &#38;#39;void setup()&#38;#39;:
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:35: error: invalid conversion from &#38;#39;int&#38;#39; to &#38;#39;uint8*&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:35: error:   initializing argument 1 of &#38;#39;uint8 HardwareSPI::send(uint8*, uint32)&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:36: error: invalid conversion from &#38;#39;int&#38;#39; to &#38;#39;uint8*&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:36: error:   initializing argument 1 of &#38;#39;uint8 HardwareSPI::send(uint8*, uint32)&#38;#39;
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp: In function &#38;#39;void loop()&#38;#39;:
&#38;lt;BUILD&#38;gt;\sketch_nov24a.cpp:45: warning: comparison between signed and unsigned integer expressions&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
