<?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() on Maple behaves different than on Arduino</title>
		<link>http://forums.leaflabs.com/topic.php?id=1174</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:07:57 +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=1174" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-26197</link>
			<pubDate>Fri, 24 May 2013 10:41:56 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">26197@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;stafil - You might get more help if you followed the posting guidelines &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=994&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=994&#60;/a&#62;&#60;br /&#62;
and gave more information about all the pieces involved in the system.&#60;/p&#62;
&#60;p&#62;In your first post you wrote:&#60;br /&#62;
&#60;em&#62;&#34;How I read buffer with 200 chars length? HardwareSerial::read(void) read only 64&#34;&#60;/em&#62;&#60;br /&#62;
in your second post you wrote:&#60;br /&#62;
&#60;em&#62;&#34;I send from PC 178 characters to maple r5 and i receive 129 chars.&#34;&#60;/em&#62;&#60;br /&#62;
in your third post you wrote:&#60;br /&#62;
&#60;em&#62;&#34;after send 186 chars from pc stm32 is stopped working.&#34;&#60;/em&#62;&#60;br /&#62;
So something is changing. What is it?&#60;/p&#62;
&#60;p&#62;What have you tried to do to diagnose the problem?&#60;/p&#62;
&#60;p&#62;For example, instead of &#60;code&#62;Serial2.print(b);&#60;/code&#62; have you tried &#60;code&#62;USBSerial.print(b);&#60;/code&#62; ?&#60;br /&#62;
Does that give different results?&#60;/p&#62;
&#60;p&#62;Have you tried connecting Serial1 and Serial2 together? Does that all work?&#60;/p&#62;
&#60;p&#62;What are you using to connect to the Maples Serial2 peripheral interface? Is it an FTDI USB-UART cable, or something else?&#60;br /&#62;
What application is sending and receiving the bytes to the Serial2 port? Is it running on Windows, Linux, OS X, Android, ...? Which version?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stafil on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-26106</link>
			<pubDate>Tue, 21 May 2013 00:40:09 +0000</pubDate>
			<dc:creator>stafil</dc:creator>
			<guid isPermaLink="false">26106@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;i work with code with maple r5, maple 0.0.12, on win8pro: &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void setup() {
    Serial2.begin(9600);
}

void echoCharacter() {
    // Check to see if we have received any information.  numUnread
    // will hold the number of bytes we&#38;#39;ve received, but haven&#38;#39;t
    // looked at yet.
    int numUnread = Serial2.available();

    // numUnread &#38;gt; 0 means that there are some unread bytes waiting
    if (numUnread &#38;gt; 0) {
        // Read a single byte out:
        byte b = Serial2.read();
        // And then print it back:
        Serial2.print(b);
    }
}

void loop() {
    echoCharacter();
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;after send 186 chars from pc stm32 is stopped working.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-26102</link>
			<pubDate>Mon, 20 May 2013 15:35:37 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">26102@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;stafil - Would you please post the programs (on pastebin or gist if it is quite long) for us to see? It is very difficult to guess what the problem might be otherwise.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stafil on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-26101</link>
			<pubDate>Mon, 20 May 2013 15:29:49 +0000</pubDate>
			<dc:creator>stafil</dc:creator>
			<guid isPermaLink="false">26101@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I send from PC 178 characters to maple r5 and i receive 129 chars.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-26100</link>
			<pubDate>Mon, 20 May 2013 13:26:39 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">26100@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;stafil - &#60;em&#62;&#34;How I read buffer with 200 chars length? HardwareSerial::read(void) read only 64.&#34;&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;&#60;code&#62;uint8 HardwareSerial::read(void)&#60;/code&#62; reads and returns one character at a time. &#60;/p&#62;
&#60;p&#62;So I don't understand your question. &#60;/p&#62;
&#60;p&#62;Would you please post an example program (on pastebin or gist if it is quite long) for us to see?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>stafil on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-26099</link>
			<pubDate>Mon, 20 May 2013 11:49:58 +0000</pubDate>
			<dc:creator>stafil</dc:creator>
			<guid isPermaLink="false">26099@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;How I read buffer with 200 chars length? HardwareSerial::read(void) read only 64.&#60;br /&#62;
thx
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-7182</link>
			<pubDate>Thu, 17 Nov 2011 13:34:38 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7182@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ala42 - interesting! So &#60;code&#62;read()&#60;/code&#62; calls &#60;code&#62;usart_getc()&#60;/code&#62; calls &#60;code&#62;rb_remove()&#60;/code&#62; but nothing checks if the buffer is empty! &#60;/p&#62;
&#60;p&#62;There is a nasty problem. &#60;code&#62;read()&#60;/code&#62; still returns a character even when the buffer is empty,&#60;br /&#62;
&#60;strong&#62;and&#60;/strong&#62; it steps the head past the tail, effectively filling the buffer with rubbish. Ooops!&#60;/p&#62;
&#60;p&#62;Assuming the recent announcement about Wiring compatibility is LeafLabs goal, then &#60;code&#62;read()&#60;/code&#62; needs to be changed. It should work in the same way as &#60;a href=&#34;http://wiring.org.co/reference/Serial_read_.html&#34;&#62;Wiring's Serial.read&#60;/a&#62; by returning a 'no characters' value, all the return types must be changed from uint8 to something bigger like an int16, to accommodate every byte value, and a distinct 'no characters' (-1) value.&#60;/p&#62;
&#60;p&#62;For example:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;static inline int16 rb_remove(ring_buffer *rb) {
    if (rb_is_empty(rb)) return -1;
    uint8 ch = rb-&#38;gt;buf[rb-&#38;gt;head];
    rb-&#38;gt;head = (rb-&#38;gt;head == rb-&#38;gt;size) ? 0 : rb-&#38;gt;head + 1;
    return ch;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>ala42 on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-7181</link>
			<pubDate>Wed, 16 Nov 2011 18:01:24 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">7181@http://forums.leaflabs.com/</guid>
			<description>&#60;pre&#62;&#60;code&#62;uint8 HardwareSerial::read(void) {
    return usart_getc(usart_device);
}

/**
 * @brief Read one character from a serial port.
 *
 * It&#38;#39;s not safe to call this function if the serial port has no data
 * available.
 *
 * @param dev Serial port to read from
 * @return byte read
 * @see usart_data_available()
 */
static inline uint8 usart_getc(usart_dev *dev) {
    return rb_remove(dev-&#38;gt;rb);
}

/**
 * @brief Remove and return the first item from a ring buffer.
 * @param rb Buffer to remove from, must contain at least one element.
 */
static inline uint8 rb_remove(ring_buffer *rb) {
    uint8 ch = rb-&#38;gt;buf[rb-&#38;gt;head];
    rb-&#38;gt;head = (rb-&#38;gt;head == rb-&#38;gt;size) ? 0 : rb-&#38;gt;head + 1;
    return ch;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;It returns no -1, but is also does not block.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>HDS on "Serialx.read() on Maple behaves different than on Arduino"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1174#post-7179</link>
			<pubDate>Wed, 16 Nov 2011 12:52:29 +0000</pubDate>
			<dc:creator>HDS</dc:creator>
			<guid isPermaLink="false">7179@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi, &#60;/p&#62;
&#60;p&#62;I found an undocumented(?) incompatibility maybe beeing worth to be taken up into the Maple IDE v0.0.12 documentation. (Caused me quite a bit of headache to find the problem...)&#60;/p&#62;
&#60;p&#62;While the Arduino Serial.read() returns immediately with -1, when there are no bytes available in the USART buffer, the corresponding function of the Maple IDE by the time now seems to be waiting (blocking) until there is a byte in the Maple USART input buffer.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
