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

		<item>
			<title>asterix on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-11781</link>
			<pubDate>Tue, 17 Jul 2012 03:52:51 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">11781@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;If your peripheral requires 5v tolerance and can only check on spi2, I'm wondering perhaps if the device requires a common earth / ground in order to work? I've found that has been the case a few times. Good luck!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-11770</link>
			<pubDate>Mon, 16 Jul 2012 20:27:41 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">11770@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Can you guys post code of how you're setting up SPI and using it?&#60;/p&#62;
&#60;p&#62;Keep in mind that, while libmaple will setup NSS for you, you must still manually toggle it (at least it did when I used SPI on a Maple last).&#60;/p&#62;
&#60;p&#62;I have made this little helper for my projects a while ago:&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;SPIHelper.c&#60;/strong&#62;&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;stdint.h&#38;gt;

#include &#38;quot;wirish.h&#38;quot;

#include &#38;quot;SPIHelper.h&#38;quot;

// SPI1 Pin Defines
#define SCK_PIN  5
#define MISO_PIN 6
#define MOSI_PIN 7

static bool spi1_initalized = false;

void SPI1_Init()
{
	if(spi1_initalized == true) return;

	uint32 cfg_flags = SPI_FRAME_MSB &#124; SPI_DFF_8_BIT &#124; SPI_SW_SLAVE &#124; SPI_SOFT_SS;

	timer_set_mode(TIMER3, TIMER_CH1, TIMER_DISABLED);
	timer_set_mode(TIMER3, TIMER_CH2, TIMER_DISABLED);

	spi_init(SPI1);

	gpio_set_mode(GPIOA, 4, GPIO_AF_OUTPUT_PP);
	gpio_set_mode(GPIOA, SCK_PIN, GPIO_AF_OUTPUT_PP);
    gpio_set_mode(GPIOA, MISO_PIN, GPIO_INPUT_FLOATING);
    gpio_set_mode(GPIOA, MOSI_PIN, GPIO_AF_OUTPUT_PP);

	spi_master_enable(SPI1, SPI_BAUD_PCLK_DIV_256, SPI_MODE_0, cfg_flags);
	spi1_initalized = true;

#ifdef USBDEBUG
	SerialUSB.println(&#38;quot;SPI1 Enabled.&#38;quot;);
#endif
}

uint8_t SPI1_Receive(uint8_t data)
{
	spi_tx(SPI1, &#38;amp;data, 1);
	while (!spi_is_rx_nonempty(SPI1));
	return (uint8_t)spi_rx_reg(SPI1);
}

void SPI1_Send(uint8_t *data, uint16_t len)
{
	while(len--)
		SPI1_Receive(*data++);
}

void SPI1_Send(uint8_t data)
{
	SPI1_Receive(data);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;&#60;strong&#62;SPIHelper.h&#60;/strong&#62;&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#ifndef __SPIHelper_H__
#define __SPIHelper_H__

void SPI1_Init();
uint8_t SPI1_Receive(uint8_t data);
void SPI1_Send(uint8_t *data, uint16_t len);
void SPI1_Send(uint8_t data);

#define SPI_SetupNSS(gpio, pin) gpio_set_mode(gpio, pin, GPIO_OUTPUT_PP)

#define SPI_SelectLow(gpio, pin) gpio-&#38;gt;regs-&#38;gt;BRR = (1 &#38;lt;&#38;lt; pin)
#define SPI_SelectHigh(gpio, pin) gpio-&#38;gt;regs-&#38;gt;BSRR = (1 &#38;lt;&#38;lt; pin)

#endif&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;With usage:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#define SPI_PORT GPIOA
#define SPI_NSS 4

SPI1_Init();
SPI_SetupNSS(SPI_PORT, SPI_NSS);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I know it ends up being redundant, as libmaple and wirish have similar functionality... but for some reason I decided mine was better a year or more ago when I wrote the above code... Don't remember now, lol.&#60;/p&#62;
&#60;p&#62;The above can easily adapted to support SPI1 and SPI2 if need-be. Alternatively, it can be used to compare between what you're doing... I know mine works, and has worked in SPI2 (though I don't have that snippet available :( Booo HDD failures).&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-11768</link>
			<pubDate>Mon, 16 Jul 2012 14:34:01 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">11768@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;AFAIK, the spi(1) example had an error, mentioned in &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1457#post-8608&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1457#post-8608&#60;/a&#62;&#60;br /&#62;
Have you done those changes too?&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of Leafabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>suso-mc on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-11766</link>
			<pubDate>Mon, 16 Jul 2012 14:12:26 +0000</pubDate>
			<dc:creator>suso-mc</dc:creator>
			<guid isPermaLink="false">11766@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I must connect a SD card shield to SPI(2) of a Maple Rev5. I put wires in correct pìns (31-&#38;gt;NSS, 32-&#38;gt;SCK, 33-&#38;gt;MISO, 34-&#38;gt;MOSI). I use the example file FileSys.ped, in wich i change the line&#60;br /&#62;
&#34;HardwareSPI spi(1);&#34;&#60;br /&#62;
with&#60;br /&#62;
&#34;HardwareSPI spi(2);&#34;&#60;br /&#62;
 And ....... DONT WORK!!&#60;br /&#62;
What is happening? When I use SPI(1) it works fine.&#60;br /&#62;
Anyone can help me?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-8652</link>
			<pubDate>Thu, 15 Mar 2012 13:41:40 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">8652@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;you may be running into that NSS issue, see this thread &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1020&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1020&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mconners on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-8609</link>
			<pubDate>Tue, 13 Mar 2012 09:42:41 +0000</pubDate>
			<dc:creator>mconners</dc:creator>
			<guid isPermaLink="false">8609@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for the response. I will try again. I just wanted to make sure I wasn't chasing something that wasn't gonna work anyway.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-8608</link>
			<pubDate>Tue, 13 Mar 2012 08:58:29 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">8608@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have been using SPI 2 on RET6 with various SPI devices.  I've only used SPI 1 a few times.  I haven't had any problems.  Though in porting Arduino SPI sketches, I had to move the pinMode(SS,OUTPUT) to after the spi.begin().  Also for some devices I had to add a delay(1) before the digitalWrite(SS,HIGH);  -- otherwise, it seemed the SPI transaction wasn't completing. I've been mainly using the lower KHz modes so I can see things with my USB scope.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mconners on "RET6 and SPI2"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1457#post-8600</link>
			<pubDate>Mon, 12 Mar 2012 18:48:17 +0000</pubDate>
			<dc:creator>mconners</dc:creator>
			<guid isPermaLink="false">8600@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Are there any known issues with SPI2 on the RET6 version of the board. I took a known good device (an sd card reader) put it on SPI 1, ran some code, worked fine.&#60;/p&#62;
&#60;p&#62;I moved the wires to SPI 2, changed the code appropriately, doesn't work. &#60;/p&#62;
&#60;p&#62;I'm basically running the FileSys sketch that came with one of the SDFat libraries.&#60;/p&#62;
&#60;p&#62;I checked my wiring alot, changed it back and forth between the two ports and each time same result, works on 1, not on 2.&#60;/p&#62;
&#60;p&#62;The issue is really that I have another device that will need the 5v tolerant pins on SPI2 but I was having no luck communicating with that, so I thought I would troubleshoot with a known good device and code.&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;MikeC
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
