<?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: SerialX.read() ring buffer</title>
		<link>http://forums.leaflabs.com/topic.php?id=2306</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:43 +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=2306" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12150</link>
			<pubDate>Wed, 01 Aug 2012 16:47:25 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12150@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;feurig: That is what I'm saying. The patch fixes the issue by waiting until data are available. This also makes SerialX behave like SerialUSB, which is nice.&#60;/p&#62;
&#60;p&#62;Edit: more precisely, I mean this: in v0.0.12, if you call SerialX.read() when SerialX.available() == 0, then you'll get a garbage character back from the read(), and the next call to available() will return 63.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>feurig on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12147</link>
			<pubDate>Wed, 01 Aug 2012 11:58:57 +0000</pubDate>
			<dc:creator>feurig</dc:creator>
			<guid isPermaLink="false">12147@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So (mbolivar) what you are saying above is that because they are reading more data than is actually available the buffers are getting corrupted therefore they are returning the 63 instead of the correct result (no data) ? It took me a while to decipher that.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12130</link>
			<pubDate>Tue, 31 Jul 2012 15:54:57 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12130@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
I was running into a similar problem with i2c and spi, mainly the bytes read were shifted out of order do these have a similar ring buffer?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;No; they don't use ring buffers. Can you open another topic with some sample code showing the bad behavior (out-of-order data)? Please try to keep the sample code short.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12129</link>
			<pubDate>Tue, 31 Jul 2012 15:53:16 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12129@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
if Serial2.available&#60;br /&#62;
Serial2.read for 12 bytes
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;That's not safe. You need to check if Serial2.available() &#38;gt;= 12 before reading 12 bytes, or you'll corrupt the ring buffer contents.&#60;/p&#62;
&#60;p&#62;This seems like it's been causing confusion. I think we should make HardwareSerial::read() block until there are bytes to read. I've pushed this into master:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/15b8a03de97078823ed431e472aedb0988d62220/&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/15b8a03de97078823ed431e472aedb0988d62220/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12116</link>
			<pubDate>Mon, 30 Jul 2012 21:05:14 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12116@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I found you can also increase the ringbuffer by modifying maple/hardware/leaflabs/cores/maple/usart.h&#60;/p&#62;
&#60;p&#62;#define USART_RX_BUF_SIZE               256 // set it to whatever you like, however if you set it too high I would imagine it might chew some resources!&#60;/p&#62;
&#60;p&#62;When you compile the ringbuffer will be increased. Set it to the max bytes you'd like to read perhaps.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>taylorapgar on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12102</link>
			<pubDate>Sun, 29 Jul 2012 09:38:48 +0000</pubDate>
			<dc:creator>taylorapgar</dc:creator>
			<guid isPermaLink="false">12102@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I switched to flushing the buffer just before writing to the device and then only read if there is exactly 12 bytes available.  It seems to be working much better now.  Thanks for getting back to me.&#60;/p&#62;
&#60;p&#62;I was running into a similar problem with i2c and spi, mainly the bytes read were shifted out of order do these have a similar ring buffer?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12101</link>
			<pubDate>Sun, 29 Jul 2012 06:48:03 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12101@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I've noted the same problem. I've also noticed that when the buffer should be empty, it still returns 63 (from what I can gather).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12100</link>
			<pubDate>Sun, 29 Jul 2012 05:44:18 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">12100@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You could always read the buffer until it's empty (using maybe a do while loop in the if statement block) or flush the buffer after you've gotten the data you want.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>taylorapgar on "SerialX.read() ring buffer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2306#post-12098</link>
			<pubDate>Sat, 28 Jul 2012 22:31:02 +0000</pubDate>
			<dc:creator>taylorapgar</dc:creator>
			<guid isPermaLink="false">12098@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;I have been having issues with the Serial.read function and I keep thinking that I fixed the problem but it keeps coming back.  I am expecting 12 bytes back from a device after I write to a register.  The program seems to run fine for a while until all of the sudden Serial.available returns 63.  After looking through the forum it sounds like the ring buffer is filled.  I am pretty sure its not the device that is causing the issue since I had it working fine with arduino.&#60;/p&#62;
&#60;p&#62;My code layout basically looks like&#60;/p&#62;
&#60;p&#62;Serial2.write()&#60;br /&#62;
if Serial2.available&#60;br /&#62;
Serial2.read for 12 bytes&#60;/p&#62;
&#60;p&#62;Is there a better way of doing this so that the ring buffer doesn't get filled?  Once this happens I am not able to tell which byte is supposed to be which.&#60;/p&#62;
&#60;p&#62;Thank you,&#60;br /&#62;
Taylor
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
