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

		<item>
			<title>snigelen on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-5088</link>
			<pubDate>Thu, 09 Jun 2011 02:51:34 +0000</pubDate>
			<dc:creator>snigelen</dc:creator>
			<guid isPermaLink="false">5088@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Yes it's good to have that documented, so you know you're in deep trouble when you see the throbbing ;-).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-5069</link>
			<pubDate>Wed, 08 Jun 2011 16:20:13 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">5069@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Nice bugfix, snigelen!&#60;/p&#62;
&#60;p&#62;Having this mixed up with SPI totally threw me off the trail.&#60;/p&#62;
&#60;p&#62;Looks like this troubleshooting entry should be generalized:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/troubleshooting.html#the-status-led-is-throbbing-and-i-can-t-upload-my-program&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/troubleshooting.html#the-status-led-is-throbbing-and-i-can-t-upload-my-program&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-5042</link>
			<pubDate>Tue, 07 Jun 2011 12:52:49 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">5042@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Haza! snigelen's right.&#60;/p&#62;
&#60;p&#62;The unhappy function causes a stack overflow which causes the &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/util.c#L58&#34;&#62;__error&#60;/a&#62; handler to be called. This then calls the &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/util.c#L112&#34;&#62;throb&#60;/a&#62; function which causes the error LED to pulsate. Guess what pin the error LED is connected to on the Maple? =].
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4756</link>
			<pubDate>Tue, 24 May 2011 11:57:55 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4756@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666,&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Looking at the libmaple spi_master.cpp example I realized that SPI doesn't handle the selecting/deslecting, so I followed what the example did and added:
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;To be fair, the SPI peripheral does support hardware slave select, but you disabled that feature by using SPI_SW_SLAVE in your cfg_flags.  I didn't have time to test out hardware NSS, so I just left things the way they were in the previous API; i.e., requiring that the caller control the chip select line.  Lazy of me, I admit, but I did at least document that fact:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/docs/lang/api/hardwarespi.html#hardwarespi-class-reference&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/hardwarespi.html#hardwarespi-class-reference&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;So, this is what seems to be happening.  You comment out the pinMode(NSS, OUTPUT), which leaves the NSS line in mode GPIO_AF_OUTPUT_PP.  But you're using software slave select, so the peripheral doesn't bother to do anything with NSS.&#60;/p&#62;
&#60;p&#62;Regarding the clock line going insane and changing the quicksort signedness, no idea without looking at your code.  Those sorts of bugs ... yuck.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>snigelen on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4755</link>
			<pubDate>Tue, 24 May 2011 11:25:40 +0000</pubDate>
			<dc:creator>snigelen</dc:creator>
			<guid isPermaLink="false">4755@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;I tested your quicksort and it seems to work. But if I change, for example, pivot to unsigned it will qo to &#34;infinite&#34; recursion, 'till stack overflow and a nice fade in/out on the LED :-(.&#60;/p&#62;
&#60;p&#62;I wouldn't use a recursive sorting algorithm on a microcontroller. I suggest you try some other sorting algorithms, they will probably be both faster and safer. How many elements do you need to sort?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4754</link>
			<pubDate>Tue, 24 May 2011 09:55:44 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4754@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'll publish everything in due time =].&#60;/p&#62;
&#60;p&#62;I'm still extremely confused why the signage in the quicksort function would influence the SPI's clock pin in the way that it did. Does anyone have any ideas? I haven't tested it separately, so it may actually be something else..
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4753</link>
			<pubDate>Tue, 24 May 2011 09:34:23 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">4753@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;wikiwikiwiki time!&#60;/p&#62;
&#60;p&#62;I have been trying to find some time to make my own LCD driver, for a &#34;LCD Huge&#34; from sparkfun. Fingers crossed we can have some graphics in a week. Its for a reflow oven, if anyone wants to build one of those. Total cost of everything was about $150.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4735</link>
			<pubDate>Mon, 23 May 2011 15:37:09 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4735@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666,&#60;/p&#62;
&#60;p&#62;Awesome!  Can't wait to see what you cook up.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4713</link>
			<pubDate>Sun, 22 May 2011 12:39:46 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4713@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm giddy with joy! Have the touch screen working with a fresh median average filter. The accuracy is outstanding.&#60;/p&#62;
&#60;p&#62;My LCD wanted to say &#60;a href=&#34;http://i.imgur.com/V5nmn.jpg&#34;&#62;hello&#60;/a&#62; to LeafLabs.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4711</link>
			<pubDate>Sun, 22 May 2011 10:52:40 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4711@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Without the pinMode/digitalWrite code for the NSS pin, the MISO line is obviously blank because the SPI device is not selected and isn't looking at the data on the MOSI line. I don't have a screenshot from the Logic Analyzer of this, but when I do include the code for the NSS pin the CS/MOSI/MISO lines stay high while the CLK line (13) pulsates at a 3.7kHz @ 10% duty cycle. Of course, as you mentioned, the LED is on because it shares the SPI1 clock pin.&#60;/p&#62;
&#60;p&#62;I'll create an empty project with just the SPI code to verify it's an issue with SPI, and not something else in my project. Though.. beside SPI, I'm not using GPIOA anywhere in my project.&#60;/p&#62;
&#60;p&#62;EDIT: Yea... I broke something somewhere. Created a new project with just the SPI components, and it works flawlessly. Time to debug the other project then.&#60;/p&#62;
&#60;p&#62;EDIT2: Here's a &#60;a href=&#34;http://i.imgur.com/que8l.png&#34;&#62;screenshot&#60;/a&#62; of what the Logic Analyzer saw. The blob around +6ms is my sampling of the TouchScreen controller. After the 5 samples I take, the clock line begins to go insane. Enable stays high, and MOSI and MISO both stay low. The square wave on CLK continues foreverever.&#60;/p&#62;
&#60;p&#62;EDIT3: Someone will have to explain this to me. I traced the problem to my quicksort function:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void quicksort(uint16_t arr[], uint16_t left, uint16_t right)
{
    uint16_t i = left, j = right;
    uint16_t tmp;
    uint16_t pivot = arr[(left + right) &#38;gt;&#38;gt; 1];

    while (i &#38;lt;= j) {
        while (arr[i] &#38;lt; pivot) i++;
        while (arr[j] &#38;gt; pivot) j--;
        if (i &#38;lt;= j)
        {
            tmp = arr[i];
            arr[i] = arr[j];
            arr[j] = tmp;
            i++;
            j--;
        }
    }

    if (left &#38;lt; j)
        quicksort(arr, left, j);
    if (i &#38;lt; right)
        quicksort(arr, i, right);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Changing the datatypes from unsigned to signed fixed the issue. Huh?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4710</link>
			<pubDate>Sun, 22 May 2011 10:35:06 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">4710@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hmm. Well first off pin13 is shared between the LED and the SPI1 CLK line, so thats probably why you are seeing the throbbing. It should probably be much faster than 3.7KHz though. spi_gpio_cfg should configure all the pins for you. The fact that the select line stays high means it must be configured as output. As to why it is not toggling on SPI reads...hmm...let me muck around a bit and get back to you.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "SPI NSS causes D13 to pulsate?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=781#post-4707</link>
			<pubDate>Sat, 21 May 2011 17:57:26 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4707@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey guys,&#60;/p&#62;
&#60;p&#62;Continuing on with my project, I'm working on getting the Maple to communicate with the ADS7843 Touch Screen Controller. I've configured SPI:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;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);
spi_gpio_cfg(true, GPIOA, 4, GPIOA, 5, 6, 7);
spi_master_enable(SPI1, SPI_BAUD_PCLK_DIV_128, SPI_MODE_0, cfg_flags);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;and wrote a simple transfer &#38;amp; read function:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;uint8_t SPI_ReceiveByte(uint8_t data)
{
	spi_tx(SPI1, &#38;amp;data, 1);
	while (!spi_is_rx_nonempty(SPI1));
	return (uint8_t)spi_rx_reg(SPI1);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;All of this was based on what HardwareSPI was doing. Unfortunately, the above doesn't work. Looking at the &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/examples/spi_master.cpp&#34;&#62;libmaple spi_master.cpp&#60;/a&#62; example I realized that SPI doesn't handle the selecting/deslecting, so I followed what the example did and added:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#define NSS 10
pinMode(NSS, OUTPUT);
delay(100);
digitalWrite(NSS, HIGH);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;then to send/read I use:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;digitalWrite(NSS, LOW);

spiRecvBuffer[0] = SPI_ReceiveByte(0xD0);
// ....

digitalWrite(NSS, HIGH);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;just after the spi init block of code. Unfortunately, now... whenever the Maple receives a few SPI samples, it causes the pin 13 LED to pulsate at 3.7kHz @ ~10% duty. It looks REALLY cool, but not what I was looking for. The moment I comment out the &#60;code&#62;pinMode(NSS, OUTPUT);&#60;/code&#62; line, everything returns back to normal, except the select line stays HIGH -- even though &#60;code&#62;spi_gpio_cfg&#60;/code&#62; was supposed to take care of that for me.&#60;/p&#62;
&#60;p&#62;Am I doing something wrong?&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
