Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino Go! Serial Communication issue with 4.2 RC5


  • Please log in to reply
11 replies to this topic

#1 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 31 May 2012 - 11:48 PM

Chris,

I'm noticing that bytes get randomly dropped when using interrupt-driven serial communication on .Net MF 4.2 RC5 (Netduino Go!)

Here's how the port is being initialized.


        public void Initialize(string port = "COM1", int baudRate = 115200, Parity parity = Parity.None, int dataBits = 8, StopBits stopBits = StopBits.One, int bufferSize = 1024) {
            Incoming = new byte[bufferSize];
            Uart = new SerialPort(port, baudRate, parity, dataBits, stopBits);
            Uart.Open();
            Uart.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            IncomingIndex = 0;
        }


The content of the interrupt handler is not important: it gets/stores data one byte at a time, checks that each frame is well formed, has the correct length and passes the payload for processing if everything is OK.

The structure of a frame is: <frame start byte><total frame length><payload><frame stop byte>
The frame length is generally less than 25 bytes.
Based on what I've seen, It seems that the first byte of <payload> is getting dropped every once in a while.
This occurs even when throttling the data throughput with an 'ack' / 'nack' after each frame.

The code sending the data frame is as follows (the offset is always 0).


        protected byte[] FrameStart = new byte[] { 0x7e, 0x00 };
        protected byte[] FrameStop = new byte[] { 0x7e };
        protected byte[] Ack = new byte[] { 0xaa };
        protected byte[] Nack = new byte[] { 0xff };

        public void Send(byte[] data, int offset, byte count){
            FrameStart[1] = (byte)(count + FrameStart.Length + FrameStop.Length);
            Uart.Write(FrameStart, 0, FrameStart.Length);
            Uart.Flush();
            Uart.Write(data, offset, count);
            Uart.Flush();
            Uart.Write(FrameStop, 0, FrameStop.Length);
            Uart.Flush();
        }


Any insight would be appreciated.

Thanks.
-Fabien.

PS: every so often, I get kicked out of the debugger while tracing through the data receiver's code.

Firmware info:



HalSystemInfo.halVersion: 4.2.0.0
HalSystemInfo.halVendorInfo: Netduino Go (v4.2.0.0 RC5) by Secret Labs LLC
HalSystemInfo.oemCode: 34
HalSystemInfo.modelCode: 177
HalSystemInfo.skuCode: 4099
HalSystemInfo.moduleSerialNumber: 00000000000000000000000000000000
HalSystemInfo.systemSerialNumber: 0000000000000000
ClrInfo.clrVersion: 4.2.0.0
ClrInfo.clrVendorInfo: Netduino Go (v4.2.0.0 RC5) by Secret Labs LLC
ClrInfo.targetFrameworkVersion: 4.2.0.0
SolutionReleaseInfo.solutionVersion: 4.2.0.0
SolutionReleaseInfo.solutionVendorInfo: Netduino Go (v4.2.0.0 RC5) by Secret Labs LLC
SoftwareVersion.BuildDate: Mar 22 2012
SoftwareVersion.CompilerVersion: 410894
FloatingPoint: True
SourceLevelDebugging: True
ThreadCreateEx: True
LCD.Width: 0
LCD.Height: 0
LCD.BitsPerPixel: 0
AppDomains: True
ExceptionFilters: True
IncrementalDeployment: True
SoftReboot: True
Profiling: False
ProfilingAllocations: False
ProfilingCalls: False
IsUnknown: False

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 June 2012 - 04:03 AM

Hi Fabien, Very interesting. We're using UART extensively and haven't seen this, so I'm wondering if it's a buffer-related issue with certain size data... Can you make a simple repro which demostrates this issue consistently (within a few runs)? Somethat perhaps that writes data loopback style or to another Netduino/HyperTerminal? Chris

#3 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 01 June 2012 - 04:38 AM

Hi Chris,

We're using UART extensively and haven't seen this, so I'm wondering if it's a buffer-related issue with certain size data...



How are you using the UART specifically (polling or interrupts?)?
COM1 or COM2?
Also, the issue doesn't appear to be related to a specific buffer boundary.

What are your thoughts on the debugger 'hanging up' issue?


In my demo, the communication is going over XBee between two Netduino Go! boards.
I'm going to be investigating this thoroughly after Maker Faire this weekend and will have a repro at some point next week but in the meantime, any specific information regarding your own COM port usage would be appreciated.

Thanks,
-Fabien.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 June 2012 - 04:56 AM

Hi Fabien,

We're using the COM port in two scenarios:
  • Relaying commands to the shield base (COM1 and COM2)
  • Reflashing STM32-baesd modules (COM1 and COM2)
Things seem to be working well in both of those circumstances. I've also been using SerialPort on the Shield Base, and that seems to be working so far. I've been using both polling and DataReceived. COM1-COM4.

Regarding the debugger hanging up...that happens sometimes with NETMF, but is fairly rare. If you can repro that on two machines, I'd _love_ to take a look at that as well.

Thank you for your detective work. KodeDaemon and/or I will be happy to identify the issue if there's a bug in the firmware.

Chris

#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 01 June 2012 - 06:59 AM

In my demo, the communication is going over XBee between two Netduino Go! boards.

XBees are known to have unreliable communication at high speeds (such as 115200), even with tweaking (packetization timeout etc.). Have you tried lower speeds? There are also possible solutions or workarounds described in Using the XBee at 115,200 Baud - UPDATED 16 March 2010.

#6 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 01 June 2012 - 07:22 AM

Hi Stan, Thanks for the pointer to this article :) I had heard this mentioned before but I had never experienced this unreliability so consistently until today. I'll experiment with lower speeds tomorrow and will report on my finding. This is unfortunate because I need all the speed I can get for an interactive Go! demo at Seattle Maker Faire this weekend. Thanks, Cheers, -Fabien.

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 01 June 2012 - 08:45 AM

P.S. Also...when you get back from Seattle Mini MakerFaire, I recommend upgrading the firmware on your Netduino Go mainboard to the production firmware. http://forums.netdui...-firmware-v420/

#8 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 01 June 2012 - 03:55 PM

Thanks Chris :) Done!

#9 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 06 June 2012 - 06:12 PM

Hi Stan, I wanted to let you know that dropping the speed down to 57.6 kbps made the XBee communication completely stable. This makes me wonder why Digi even bothers advertising that 115.2 kbps is supported when it's really not working well at all... Live and learn I guess ;) Cheers, -Fabien.

#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 06 June 2012 - 06:35 PM

Thanks for the update - I saw in your Mini Maker Faire video that you managed to get it work, so I was curious how you did it.


This makes me wonder why Digi even bothers advertising that 115.2 kbps is supported when it's really not working well at all...

I guess it works fine in their test lab Posted Image

#11 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 06 June 2012 - 06:36 PM

Yeah, I saw that... Pretty impressive test rig. I guess they omitted that specific test case though ;)

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 June 2012 - 08:21 PM

I wanted to let you know that dropping the speed down to 57.6 kbps made the XBee communication completely stable.
This makes me wonder why Digi even bothers advertising that 115.2 kbps is supported when it's really not working well at all... Live and learn I guess ;)

The LED display was a really neat XBee demo!

It's quite possible that 115.2 kbps (plus packet overhead and wireless retries) is really close to the edge of the 802.15.4 envelope. They should probably include a requirement to use flow conrol (either hardware or software) with speeds that high.

Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.