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

		<item>
			<title>scott on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12470</link>
			<pubDate>Thu, 16 Aug 2012 17:19:07 +0000</pubDate>
			<dc:creator>scott</dc:creator>
			<guid isPermaLink="false">12470@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Oh, actually I didn't. I just set it to input, but forgot to write the pin to HIGH... I'll see what that does.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12459</link>
			<pubDate>Wed, 15 Aug 2012 20:52:50 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">12459@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Did you enable the pull up resistor for the NSS input for the Arduino?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>scott on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12458</link>
			<pubDate>Wed, 15 Aug 2012 20:30:12 +0000</pubDate>
			<dc:creator>scott</dc:creator>
			<guid isPermaLink="false">12458@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;looks like &#60;code&#62;pinMode(theNSSpin, OUTPUT_OPEN_DRAIN);&#60;/code&#62; Did the trick. Also set MISO to output and MOSI/NSS/SLCK to input on Arduino. And going through the 2nd SPI to be safe re~5V tolerance.&#60;/p&#62;
&#60;p&#62;@Pico - for what it's worth I called that after spi.begin()&#60;/p&#62;
&#60;p&#62;Thanks a ton!&#60;/p&#62;
&#60;p&#62;So that solved most of the issue. Getting pretty rare(ish) sporadic errors - will run things for a while tomorrow and make a rough bit-error-rate calc. I wonder if adding some (opto)isolators between controllers might help with that. Anyways, not a big deal at this point - this system is now totally usable for the purposes of my application.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12448</link>
			<pubDate>Wed, 15 Aug 2012 12:46:44 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12448@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;scott:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Going by the datasheet - yes. The threshold for a high reading on an Arduino (Uno) is 0.6Vcc(*5) = 3 Volts. Might that be close enough to 3.3V for noise artifacts to effect things?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Not sure. Do the two boards have a shared ground?&#60;/p&#62;
&#60;p&#62;pico:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
What pinMode does SPI.begin() use by default?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;It ends up calling spi_config_gpios(), which uses the gpio.h interface. The actual mode depends on the pin. On Maple, here's what happens:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/d71254f8f9047074070fff06c12cfcf07521e19b/libmaple/stm32f1/spi.c#L57&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/d71254f8f9047074070fff06c12cfcf07521e19b/libmaple/stm32f1/spi.c#L57&#60;/a&#62;&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
(I've often wondered why so many code examples show explicit pinMode() setting of the spi pins before calling SPI.begin()... is this really needed?)&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;To handle NSS by yourself (which you currently have to), you need to pinMode(theNSSPin, OUTPUT). For the other pins, it's not necessary. See discussion here:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=2391&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=2391&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>pico on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12442</link>
			<pubDate>Wed, 15 Aug 2012 08:46:07 +0000</pubDate>
			<dc:creator>pico</dc:creator>
			<guid isPermaLink="false">12442@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#34;after you setup the SPI ports, change the output pins (mosi and sclk) to open drain like this:&#34;&#60;/p&#62;
&#60;p&#62;When you say &#34;after&#34;, do you mean after SPI.begin()?&#60;/p&#62;
&#60;p&#62;What pinMode does SPI.begin() use by default? (I've often wondered why so many code examples show explicit pinMode() setting of the spi pins before calling SPI.begin()... is this really needed?)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12428</link>
			<pubDate>Tue, 14 Aug 2012 20:13:03 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">12428@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;If the arduino is running at 5V, you could be damaging the maple's microcontroller on the MISO pin if it's directly connected to the Arduino. Something like a voltage divider would prevent damage. The other option is to use the 2nd SPI port on the maple which has 5V-tolerance pins. The other option I can suggest is after you setup the SPI ports, change the output pins (mosi and sclk) to open drain like this:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
&#60;blockquote&#62;pinmode(BOARD_SPI2_MOSI_PIN, OUTPUT_OPEN_DRAIN);&#60;br /&#62;
pinmode(BOARD_SPI2_SCK_PIN, OUTPUT_OPEN_DRAIN);&#60;/blockquote&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;I'd also do the same for your CS/NSS pin. And lastly you'd need to make sure the Arduino pins have the pull resistors enabled (this is done by setting them up as an input and then doing digitalWrite(&#38;lt;pinnumber&#38;gt;,HIGH); which will enable the pull up resistor). This means the Arduino will provide the 5V for a logic high and the maple will 'drag' it down to low when required. Just remember that this can only be used for pins which are 5V tolerant.&#60;/p&#62;
&#60;p&#62;Just a note, I haven't test this setup before but believe it should work without causing damage to either microcontroller.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>scott on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12426</link>
			<pubDate>Tue, 14 Aug 2012 17:24:27 +0000</pubDate>
			<dc:creator>scott</dc:creator>
			<guid isPermaLink="false">12426@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Going by the datasheet - yes. The threshold for a high reading on an Arduino (Uno) is 0.6Vcc(*5) = 3 Volts. Might that be close enough to 3.3V for noise artifacts to effect things? I would try adding in a Low-Pass-Filter/bypass caps, but not exactly sure how to wire it up/which lines count.&#60;/p&#62;
&#60;p&#62;This is sad, but I don't have access to a Oscope or DAQ, for proper debugging :/
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12425</link>
			<pubDate>Tue, 14 Aug 2012 16:38:19 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12425@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Do the Arduino's pins correctly interpret 3.3V as logic/clock HIGH? If not, you may need a level converter.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>scott on "MapleArduino SPI Error Rate"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2439#post-12421</link>
			<pubDate>Tue, 14 Aug 2012 11:27:50 +0000</pubDate>
			<dc:creator>scott</dc:creator>
			<guid isPermaLink="false">12421@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey all -&#60;/p&#62;
&#60;p&#62;I'm working on having a maple drive an arduino through SPI, but am getting lots of/odd errors . I've got Arduino&#38;lt;&#38;gt;Arduino SPI communication down with a only few errors (i.e maybe a single error for several hundred+ transmissions) following &#60;a href=&#34;http://www.gammon.com.au/forum/?id=10892&#34; rel=&#34;nofollow&#34;&#62;http://www.gammon.com.au/forum/?id=10892&#60;/a&#62;. When I run the same thing between the maple and arduino (ensuring that the SPI settings are the same), stuff transmits, but I'm getting about 3 or 4 good transmissions, a big several second delay, then some garbage, then the whole cycle repeats. This occurs regardless of the delay I use between the Master(maple) transmitting. I also tried out all of the possible SPI-clockspeed/mode combinations. Any thoughts/ideas? &#60;/p&#62;
&#60;p&#62;I should mention - everything is directly wired from maple&#38;lt;&#38;gt;arduino, with nothing else. Should I try adding bypass caps/low-pass-filters? If so, not sure where/how I should place 'em...&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;Here's my maple code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;SPI.h&#38;gt;

HardwareSPI spi(1);

void setup (void)
{
  pinMode(ss1,OUTPUT);
  digitalWrite(ss1, HIGH);  // ensure SS stays high for now

  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  spi.begin(SPI_1_125MHZ, MSBFIRST, 0);

}  // end of setup

void loop(void)
{
  dostuff();
  delay(3000);
}  

void dostuff(){
  char c;
  for (const char * p = &#38;quot;ping\n&#38;quot; ; c = *p; p++){
    spi.write(c);
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Here's my arduino code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;SPI.h&#38;gt;

char buf [100];
volatile byte pos;
volatile boolean process_it;

void setup (void)
{
  Serial.begin (19200);   // debugging

  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);

  // turn on SPI in slave mode
  SPCR &#124;= _BV(SPE);

  // get ready for an interrupt
  pos = 0;   // buffer empty
  process_it = false;

  // now turn on interrupts
  SPI.attachInterrupt();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);

}  // end of setup

// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR;  // grab byte from SPI Data Register

  // add to buffer if room
  if (pos &#38;lt; sizeof buf)
    {
    buf [pos++] = c;

    // example: newline means time to process buffer
    if (c == &#38;#39;\n&#38;#39;)
      process_it = true;

    }  // end of room available
}  // end of interrupt routine SPI_STC_vect

// main loop - wait for flag set in interrupt routine
void loop (void)
{
  if (process_it)
    {
    buf [pos] = 0;
    Serial.println (buf);
    pos = 0;
    process_it = false;
    }  // end of flag set

}  // end of loop&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
