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

		<item>
			<title>mbolivar on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12131</link>
			<pubDate>Tue, 31 Jul 2012 16:02:02 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12131@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
void loop()&#60;br /&#62;
{&#60;br /&#62;
int numberOfBytes = Serial2.available();&#60;br /&#62;
Serial2.write (numberOfBytes);&#60;br /&#62;
}&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I can't reproduce this issue using the following program:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void setup() {
    Serial2.begin(115200);
}

void loop() {
    int available = Serial2.available();
    Serial2.println(available);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;When I connect to Serial2, I see 0 printed, which is what I expect. Each time I send a character, the printed number increases by 1 until it hits 63, which is the size of the ring buffer the serial ports use. At that point, it stays 63 no matter how many characters I send. Things seem to work for me.&#60;/p&#62;
&#60;p&#62;Can you please send a short, complete program that exhibits the bug? Along with the program, please explain what you expect to happen, and what happens instead.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12090</link>
			<pubDate>Sat, 28 Jul 2012 11:01:42 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12090@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Unless of course WiFly is limiting the buffer size...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12089</link>
			<pubDate>Sat, 28 Jul 2012 09:43:49 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12089@http://forums.leaflabs.com/</guid>
			<description>&#60;br /&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12088</link>
			<pubDate>Sat, 28 Jul 2012 09:41:19 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12088@http://forums.leaflabs.com/</guid>
			<description>&#60;br /&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12087</link>
			<pubDate>Sat, 28 Jul 2012 09:36:39 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12087@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have managed to solve the problem (I believe) and I may need to submit a bug report (how do I do this??). But actually it was a two part problem, which probably doesn't need to be covered here.&#60;/p&#62;
&#60;p&#62;Serial.available bug //////////&#60;/p&#62;
&#60;p&#62;The Serial library must only store up to 64 bytes into its memory buffer, as the maximum number of bytes I can read is always 63 (I'm assuming its reading off an array).&#60;/p&#62;
&#60;p&#62;When there are no bytes available, Serial.available returns innacurately, as 63. You can test this by a simple sketch:&#60;/p&#62;
&#60;p&#62;void loop()&#60;br /&#62;
{&#60;br /&#62;
 int numberOfBytes = Serial2.available();&#60;br /&#62;
 Serial2.write (numberOfBytes);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Somewhere along the line, I am still getting a double sent variable. Still trying to figure out why exactly but I know its double sent because otherwise the array of data I'm recieving wouldn't be perfectly formed and all of my shiftbrites wouldn't be lighting up!!!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12025</link>
			<pubDate>Thu, 26 Jul 2012 08:21:02 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">12025@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;asterix&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I believe I've nutted out a reasonable send rate ...&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;So, let me make sure I understand.&#60;br /&#62;
If the transfer is slow enough, everything transfers with 100% accuracy over the USART in either direction?&#60;/p&#62;
&#60;p&#62;Have you looked at &#60;a href=&#34;http://en.wikipedia.org/wiki/IEEE_802.11_RTS/CTS&#34; rel=&#34;nofollow&#34;&#62;http://en.wikipedia.org/wiki/IEEE_802.11_RTS/CTS&#60;/a&#62;&#60;br /&#62;
Depending on how Rover Networks implement things, that seems to explain what might be happening on the wireless side, but I have not read the WiFly documentation enough to know, so I may be misleading you.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-12020</link>
			<pubDate>Thu, 26 Jul 2012 01:59:44 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">12020@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I am sending via TCP / IP so I'm expecting 100% accuracy. An external antenna I hacked out of an old laptop seems to have helped rather than relying on the chip antenna.&#60;/p&#62;
&#60;p&#62;I believe I've nutted out a reasonable send rate but can always be improved by the higher baud rates offered by SPI. I'm curious to find out more about RTS / CTS as roving networks point out that it is generally a good idea for large packet streams or constant packet streams.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-11993</link>
			<pubDate>Wed, 25 Jul 2012 08:50:08 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">11993@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;asterix - I am not a WiFly guru.&#60;/p&#62;
&#60;p&#62;In my experience, either the person with the bug spots the error when they explain it, or it becomes clear to someone who has had a similar bug before what is happening, so I asked for a bit more detail.&#60;/p&#62;
&#60;p&#62;I would do my best to avoid using RTS &#38;amp; CTS, if I could. It is even more complexity to get right. I can imagine that the WiFly might resend a character if RTS/CTS are wiggled. Otherwise I would expect the WiFly to only deliver each character once.&#60;/p&#62;
&#60;p&#62;I notice that the code doesn't check for a 'V' on each byte, so once it loses synchronisation, it might be a long time before it gets it back. It might be worth checking every byte for 'V', and now 'Q'. &#60;/p&#62;
&#60;p&#62;It might also be worth sending a smaller packet. Try making every packet unique (in some simple way). For example, use a 16 bit into to count the packets, and convert that int to 4 hexadecimal ASCII characters ('0' to '9' and 'A' to 'F'). Then wait, don't send anything more for a big chunk of a second.&#60;/p&#62;
&#60;p&#62;How are you opening the connection to the WiFly on the host? Is it a TCP/IP socket connection, or UDP?&#60;/p&#62;
&#60;p&#62;TCP/IP should not pass the packet on until it is sure that the packets are correct and in the correct order. So losing packets sounds very strange if TCP/IP is being used.&#60;br /&#62;
TCP/IP will balance the size of a packet with a time out, so a small packet may take longer to deliver, and several might arrive in one chunk.&#60;br /&#62;
UDP will do best efforts only.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-11992</link>
			<pubDate>Wed, 25 Jul 2012 08:23:54 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">11992@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer, sorry busy week!&#60;/p&#62;
&#60;p&#62;I've only posted an edited down version of the sketch as there was alot of other stuff that isnt relevant.&#60;/p&#62;
&#60;p&#62;I basically just added an else clause to my if (someByte == 'V') to check whether it was in time or not. If its not a V that I'm recieving before my loop then I've either lost or gained a char. I send it back to processing to notify me. The odd thing is that if one packet in the series (as I'll explain below) is out of synch, then I should be receiving at least several responses on every scan sent through. Not just one bad char every second scan or so.&#60;/p&#62;
&#60;p&#62;I'm basically sending a series of 5 bytes: V int char char char (without spaces of course). I am doing this 26 times per send, each of the 26 times is basically captured by maple and the last three chars are fed into an array but stored as an int value. int r= Serial2.read();&#60;/p&#62;
&#60;p&#62;V - to verify that the order of the bytes is correct.&#60;/p&#62;
&#60;p&#62;int - Introduced after this post was originally written. An integer identifying what number in the array the chars should be assigned to (i could use a counter but I want to be certain the array is assigned correctly. This is sent from processing as a char by using char(i) in a loop. I add 10 to avoid any problems with char(0) through to 10 (char(0) is NULL which sounds bodgy to me!!).&#60;/p&#62;
&#60;p&#62;char char char -  I read these as ints although they are sent out as chars. Chars are just a convenient way for me to send values between 0 and 255. I'm basically sending an RGB value in for each array item.&#60;/p&#62;
&#60;p&#62;I send this format through 26 times per ip frame. Doesn't seem to matter if I send each of the 26 seperatly or in one ip packet frame as a String.&#60;/p&#62;
&#60;p&#62;At the trailing end I send another char ('Q') which, when added to the if (someByte = 'V') clause will trigger another char ? to be sent back to processing to tell it to send the next line. I've ended up ditching this now and just flushing the Serial buffer entirely which seems to have improved data speeds. Q also triggers another function that shifts the array out into my shiftbrite leds (which you've helped me with before).&#60;/p&#62;
&#60;p&#62;What I really don't understand with WiFly is how it talks through UART. Before I had to send my string through twice before recieving a '?' response back from maple, which means either:&#60;br /&#62;
- WiFly isn't sending the data through the UART until the buffer is full&#60;br /&#62;
- My data has corrupted and 'Q' never made it through.&#60;br /&#62;
I've reduced the flush size to around 150 and I only need to send the string once to get processing to automatically resend each 26 lines.&#60;/p&#62;
&#60;p&#62;Anyway, RTS/CTS is a little confusing and their documentation doesn't help. Its confusing as I'm not sure what side of the wifly I am controlling:&#60;/p&#62;
&#60;p&#62;- Is it controlling when to send / receive from serial uart to wifly&#60;br /&#62;
- Is it telling when wifly should send / receive to the host connection (my laptop running processing in this case).&#60;/p&#62;
&#60;p&#62;Hope this makes sense. perhaps I should just post up my code...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-11939</link>
			<pubDate>Mon, 23 Jul 2012 12:32:29 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">11939@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;asterix - could you give a bit more information?&#60;/p&#62;
&#60;p&#62;As far as I can tell from the example code, in post 2, you've only tried receiving data. Is that true? Is the doubling up or lost bytes always when receiving, or transmitting data, or are both directions effected in either way?&#60;/p&#62;
&#60;p&#62;How do you detect that the data is lost or doubled up? The code in post 2 doesn't seem to have anyway to detect or signal that.&#60;/p&#62;
&#60;p&#62;How many bytes get through before the errors? Are the some number of bytes which get through?&#60;/p&#62;
&#60;p&#62;If you use a very low baud rate (e.g. 1200 baud), is the problem as common as a high baud rate (e.g. 921600)?&#60;/p&#62;
&#60;p&#62;Are the byte values sent/received always correct, or are they sometimes wrong too?&#60;/p&#62;
&#60;p&#62;In general, you have two choices with hardware handshaking, either program the USART to do it, or do it yourself in software. That code looks like it is trying a bit of both.&#60;/p&#62;
&#60;p&#62;What happens on low-speed comms with no flow control? AFAICT from the RN131 datasheet, it doesn't need flow control. Can you 'throttle' the software sending data so that it is very slow, so flow-control can't possibly have an effect?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-11926</link>
			<pubDate>Sun, 22 Jul 2012 23:58:20 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">11926@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here is my sketch. Does it appear I'm using CTS correctly to control data being recieved?&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
#include &#38;lt;stdlib.h&#38;gt;&#60;/p&#62;
&#60;p&#62;#define NumLEDs 24&#60;br /&#62;
#define RTS_PIN 10 // RTS PIN&#60;br /&#62;
#define CTS_PIN 11 // CTS PIN&#60;/p&#62;
&#60;p&#62;uint8 LEDChannels[NumLEDs][3] = {0};&#60;/p&#62;
&#60;p&#62;void setup()&#60;br /&#62;
{&#60;br /&#62;
  pinMode(RTS_PIN, OUTPUT);&#60;br /&#62;
  pinMode(CTS_PIN, INPUT);&#60;br /&#62;
  USART3-&#38;gt;regs-&#38;gt;CR3 = (USART_CR3_CTSE &#124; USART_CR3_RTSE); // IS THIS RIGHT IF IM USING SERIAL 2??&#60;br /&#62;
  Serial2.begin(921600);&#60;br /&#62;
  for (int h = 0; h &#38;lt;  NumLEDs; h++)&#60;br /&#62;
  {&#60;br /&#62;
	  LEDChannels[h][0] = 10;&#60;br /&#62;
	  LEDChannels[h][1] = 10;&#60;br /&#62;
	  LEDChannels[h][2] = 255;&#60;br /&#62;
  }&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void loop()&#60;br /&#62;
{&#60;br /&#62;
  digitalWrite(CTS_PIN,LOW); // turn CTS on to open UART data&#60;br /&#62;
    if (Serial2.available() &#38;gt; 0  )&#60;br /&#62;
    {&#60;/p&#62;
&#60;p&#62;     someByte = Serial2.read();&#60;/p&#62;
&#60;p&#62;     if (someByte == 'V')&#60;br /&#62;
      {&#60;/p&#62;
&#60;p&#62;                    for (int i=0; i &#38;lt; 8; i++)&#60;br /&#62;
                    {&#60;br /&#62;
                    int num = Serial2.read();&#60;br /&#62;
                    num -= 10;&#60;br /&#62;
                    LEDChannels[num][0] = getByte();&#60;br /&#62;
                    LEDChannels[num][1] = getByte();&#60;br /&#62;
                    LEDChannels[num][2] = getByte();&#60;br /&#62;
                    }&#60;br /&#62;
                    digitalWrite(CTS_PIN, HIGH); // tell CTS to turn off&#60;/p&#62;
&#60;p&#62;        } // if N&#60;/p&#62;
&#60;p&#62;    } // Serial Available&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;int getByte()&#60;br /&#62;
{&#60;br /&#62;
  return Serial2.read();&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>asterix on "RTS / CTS - WiFly"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2240#post-11918</link>
			<pubDate>Sun, 22 Jul 2012 18:35:33 +0000</pubDate>
			<dc:creator>asterix</dc:creator>
			<guid isPermaLink="false">11918@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi team, &#60;/p&#62;
&#60;p&#62;I've noticed that in &#60;a href=&#34;http://leaflabs.com/docs/hardware/maple-mini.html&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple-mini.html&#60;/a&#62; it notes that for Serial2 pins 10 and 11 are RTS / CTS respectively. Is there any harward flow control built into maple? Does it need to be initiated somehow?&#60;/p&#62;
&#60;p&#62;I'm looking into hardware flow control for a WiFly RN131 module which seems to be either dropping or doubling up data, even on lower baud rates.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
