<?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: How could I know whether my SPI buffer is overflow or not?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1066</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:24:13 +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=1066" rel="self" type="application/rss+xml" />

		<item>
			<title>gulu2065 on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6603</link>
			<pubDate>Mon, 26 Sep 2011 01:21:08 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6603@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;br /&#62;
I have figure it out.&#60;br /&#62;
Thanks for your kind help!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6600</link>
			<pubDate>Sun, 25 Sep 2011 17:30:16 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6600@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;br /&#62;
Thank, that code works!&#60;br /&#62;
Now there is no doubt that it is overflow. I am trying to use DMA so solve this problem. But I can't figure out how to do it.&#60;br /&#62;
Can you have a look at this ?&#60;br /&#62;
thanks&#60;br /&#62;
&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=1072&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=1072&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6599</link>
			<pubDate>Sun, 25 Sep 2011 17:08:06 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6599@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gulu2065 - what is the error message?&#60;/p&#62;
&#60;p&#62;It might be something earlier in the file.&#60;/p&#62;
&#60;p&#62;do you get the same error if you change it to:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;bool hasOverrunOccurred() {
    // return SPI1_BASE-&#38;gt;SR &#38;amp; SPI_SR_OVR;
   return 0xFFFFFFFF;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6575</link>
			<pubDate>Sun, 25 Sep 2011 00:22:36 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6575@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi glulmer,&#60;br /&#62;
Besides, when I compile this sentence, it shows error.&#60;br /&#62;
do you know what the problem is?&#60;br /&#62;
bool hasOverrunOccurred() {&#60;br /&#62;
    return SPI1_BASE-&#38;gt;SR &#38;amp; SPI_SR_OVR;&#60;br /&#62;
}&#60;br /&#62;
Thanks,
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6574</link>
			<pubDate>Sat, 24 Sep 2011 22:00:28 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6574@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi glulmer,&#60;br /&#62;
It seems the RAM is not that big. When I compile this, it show this error. I guess the buffer is too big, right?&#60;br /&#62;
elf section &#60;code&#62;.bss&#38;#39; will not fit in region&#60;/code&#62;ram'&#60;br /&#62;
c:/users/guo/desktop/maple/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/bin/ld.exe: region `ram' overflowed by 1096 bytes&#60;/p&#62;
&#60;p&#62;Can I store the data in the flash, I see it is much bgiger than the RAM.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6566</link>
			<pubDate>Sat, 24 Sep 2011 17:52:25 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6566@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gulu2065 - I had understood that your use case would allow the program to capture the data, store it, then upload it.&#60;br /&#62;
Is that not the case? &#60;/p&#62;
&#60;p&#62;If you can store it, try something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;byte buff[16422];
int i=0;
void loop() {
    buff[i++] = spi.read();
    if (i&#38;gt;= sizeof(buff)) {
        // Print out the response received.
        for (int j=0; j&#38;lt;i; j++) {
            SerialUSB.println(response, BIN);
        }
        i=0;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(usual WARNINGS: I have not compiled or tested this code)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6557</link>
			<pubDate>Sat, 24 Sep 2011 14:30:46 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6557@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;No, unfortunately, the USB serial port is not very fast.  The USB peripheral is quite fast, but we don't have the necessary library support for fast transfers over USB yet.&#60;/p&#62;
&#60;p&#62;And I'm sorry, but I don't know enough about your application to know when you have to tear down your SPI port. Is it very important never to miss a byte? If so, I guess you'd need to stop as soon as the first overrun condition happens. If it's not that important, then maybe you can recover from the error somehow.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6556</link>
			<pubDate>Sat, 24 Sep 2011 14:25:20 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6556@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I guess the USB serial is not fast enough as to reach 1.6Mhz.&#60;br /&#62;
How could I know when should I end the SPI in case of overflow?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6555</link>
			<pubDate>Sat, 24 Sep 2011 14:24:40 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6555@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;If you have an unread byte, and the SPI master sends another one, then you get an &#34;overrun condition&#34;.  The second byte sent is lost.&#60;/p&#62;
&#60;p&#62;You can check if this has happened by checking the OVR flag in the status register (SR) for the SPI peripheral you're interested in, using this function:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;bool hasOverrunOccurred() {
    return SPI1_BASE-&#38;gt;SR &#38;amp; SPI_SR_OVR;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;&#60;code&#62;hasOverrunOccurred()&#60;/code&#62; will return &#60;code&#62;true&#60;/code&#62; if you've missed a byte, and &#60;code&#62;false&#60;/code&#62; otherwise.&#60;/p&#62;
&#60;p&#62;If that happens, you need to clear the OVR flag in the status register. If you don't, then you won't be able to detect later overruns anymore -- &#60;code&#62;hasOverrunOccurred()&#60;/code&#62; will just return &#60;code&#62;true&#60;/code&#62; forever.&#60;/p&#62;
&#60;p&#62;You clear the OVR flag by reading the first unread byte, then reading the status register again. Here's some (untested) code that should do the trick:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Read the unread byte
byte unread = spi.read();
// Read the status register
uint32 sr = SPI1_BASE-&#38;gt;SR;&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "How could I know whether my SPI buffer is overflow or not?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1066#post-6554</link>
			<pubDate>Sat, 24 Sep 2011 14:11:02 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6554@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I use the SPI work on slave and read data from another chip. Here is my code.&#60;/p&#62;
&#60;p&#62;HardwareSPI spi(1);&#60;br /&#62;
...&#60;br /&#62;
void setup() {&#60;br /&#62;
....&#60;br /&#62;
spi.beginSlave(MSBFIRST, 0);&#60;br /&#62;
}&#60;br /&#62;
void loop() {&#60;br /&#62;
   byte response = spi.read();&#60;br /&#62;
   // Print out the response received.&#60;br /&#62;
   SerialUSB.println(response, BIN);&#60;br /&#62;
 }&#60;/p&#62;
&#60;p&#62;It read data at the speed of 1.6Mhz.&#60;br /&#62;
Thanks
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
