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

Help on Netduino 2 Serial Communication to PC

netduino 2 RS232 communication

Best Answer Chris Walker, 21 July 2015 - 05:10 AM

Hi yxhu,

First steps to debug:
1. What serial cable are you using from your PC? Is it a 5V or 3.3V TTL (not RS-232 cable)? Netduino's serial signals are 3.3V (with 5V tolerance) -- so RS-232 levels (-15V to 15V) are not safe and won't give you good data.
2. Have you tried 115,200 bps or 57,600 bps, as a test?
3. Have you connected GND between your Netduino and your PC's serial cable? If you have your Netduino plugged into your PC this may be redundant (since your USB cable is already carrying the ground signal) but it is best practice--and it is required if the two devices are not already sharing a ground reference/connection.

Welcome to the Netduino community,

Chris Go to the full post


  • Please log in to reply
2 replies to this topic

#1 yxhu

yxhu

    New Member

  • Members
  • Pip
  • 3 posts

Posted 18 July 2015 - 02:58 PM

Hi Chris,
 
I am new to this forums and this is my first post. Recently I have purchased a few ND2s. I setup a very small serial communication program and unfortunatey it didn't work as expected. Here is the setting:
 
On netduino, I am using COM4, the connection to the PC as:
 
ND            ----->  PC
 
SDA(RX)   ----     TX
SCL (TX)   ----     RX
 
 
Program runs on the ND:
 

private static SerialPort _serialPort;

public static void Main()
{
   _serialPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
   _serialPort.Open();

    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
    byte[] bytesToSend  = encoder.GetBytes("abc");

    while(true){
       _serialPort.Write(bytesToSend, 0, bytesToSend.Length);
    }
}

 
 
Program runs on the PC:
 

public Program()
{
    _serialPort = new SerialPort();
    _serialPort.PortName     = "COM3";
    _serialPort.BaudRate     = 9600;
    _serialPort.DataBits     = 8;
    _serialPort.DiscardNull  = true;
    _serialPort.StopBits     = StopBits.One;
    _serialPort.Parity       = Parity.None;
    _serialPort.DataReceived += _serialPort_DataReceived;
    _serialPort.Open();
}

private void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
     var _buffer = new byte[_serialPort.BytesToRead];
      _serialPort.Read(_buffer, 0, _buffer.Length);

     Console.WriteLine(System.Text.ASCIIEncoding.UTF8.GetString(_buffer));
}

  
Basically, I wanted to let ND to keep sending string "abc" to the PC. After I have tried different Baud rates, i.e.  9600, 4800, 2400. I am always getting very wired result at PC end, please see the attached screenshot.

 

I suspect there might be the Baud rate mismatch. However, I have tripple checked my code, both sides have identical settings on the serial port.

 

I spent many hours googling with no luck.

 

 

On other weird thing was, I needed to set 'DiscardNull = true' on the PC end, otherwise I am getting massive '0x00' bytes from ND.

 

I am using VS2010, Micro Framework 4.2, Netdunio SDK 4.2.2.2. I started with VS2013, Micro Framework 4.3, and Netduino SDK 4.3.2.1, unforturnately I couldn't debug the program on ND. I always get error  "The debuging target is not in an initialized state; rebooting......", So I have reverted everything back to VS2010, then I could debug the program.

 

I have also attached the output from "Device capabilities" in the MSDeploy FYI.

 

 

 

 

 

 

 

 

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 21 July 2015 - 05:10 AM   Best Answer

Hi yxhu,

First steps to debug:
1. What serial cable are you using from your PC? Is it a 5V or 3.3V TTL (not RS-232 cable)? Netduino's serial signals are 3.3V (with 5V tolerance) -- so RS-232 levels (-15V to 15V) are not safe and won't give you good data.
2. Have you tried 115,200 bps or 57,600 bps, as a test?
3. Have you connected GND between your Netduino and your PC's serial cable? If you have your Netduino plugged into your PC this may be redundant (since your USB cable is already carrying the ground signal) but it is best practice--and it is required if the two devices are not already sharing a ground reference/connection.

Welcome to the Netduino community,

Chris

#3 yxhu

yxhu

    New Member

  • Members
  • Pip
  • 3 posts

Posted 24 July 2015 - 06:28 AM

Hi Chris,

 

Thank you so much for shedding the light on this one....  I have resolved issue by replacing the MAX232 as it was malfunction. Usually MAX232 quite stable didn't know why for this instance it stopped work. Maybe I am just too new to this Netduino world and got bully by this small piece of chip. :D

 

yx







Also tagged with one or more of these keywords: netduino 2, RS232, communication

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.