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

Serial Issues

UART

Best Answer jonlf, 01 August 2014 - 09:14 PM

Boy do I feel stupid.  It was a line level issue.  Thanks for the second set of eyes on something I should have known to look at more closely.

Go to the full post


  • Please log in to reply
9 replies to this topic

#1 jonlf

jonlf

    New Member

  • Members
  • Pip
  • 4 posts

Posted 21 July 2014 - 07:27 PM

I am just getting started with an N+2 and am seeing some odd behavior when collecting serial data.  Below is the code I am using to collect data on COM1.

private static SerialPort _port;

public static void Main()
{
	_port = new SerialPort(SerialPorts.COM1, 9600);
	_port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
	_port.Open();

	Debug.Print("Start scanning!");
	Thread.Sleep(Timeout.Infinite);
}

private static void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
	while (_port.BytesToRead > 0)
	{
		var data = _port.ReadByte();
		Debug.Print(data.ToString());
	}
}

The serial output is coming from a PC running Putty.  I have tested PC to PC and am getting the ASCII values I expect.  However, when sent to the N+2 I get the following codes...

Char	ASCII
0	6
1	103
2	51
3	102
4	25
5	101
6	50
7	100
8	12
9	99	

I tried working it out on paper to see if it was an endian issue or bit inversion but am not seeing it.  Can anyone help point me in the right direction?  I must be missing something very simple.  Just in case I have included the dump from my Device Capabilities.  I appreciate any help you guys can provide.

Not Supported
Not Supported
Not Supported
Not Supported
Connecting to NetduinoPlus2_Netduino...Connected
HalSystemInfo.halVersion:               4.2.0.0
HalSystemInfo.halVendorInfo:            Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC
HalSystemInfo.oemCode:                  34
HalSystemInfo.modelCode:                177
HalSystemInfo.skuCode:                  4102
HalSystemInfo.moduleSerialNumber:       00000000000000000000000000000000
HalSystemInfo.systemSerialNumber:       0000000000000000
ClrInfo.clrVersion:                     4.2.0.0
ClrInfo.clrVendorInfo:                  Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC
ClrInfo.targetFrameworkVersion:         4.2.0.0
SolutionReleaseInfo.solutionVersion:    4.2.2.2
SolutionReleaseInfo.solutionVendorInfo: Netduino Plus 2 (v4.2.2.2) by Secret Labs LLC
SoftwareVersion.BuildDate:              Jan 26 2013
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:                             False
Profiling:                              False
ProfilingAllocations:                   False
ProfilingCalls:                         False
IsUnknown:                              False


#2 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 22 July 2014 - 04:35 PM

N/m putty.  Baud mismatch maybe?

 

Isn't there some concern using com1 while the debugger is running? I thought you had to jump through hoops to get it to work at all, so I've always just used ethernet.



#3 jonlf

jonlf

    New Member

  • Members
  • Pip
  • 4 posts

Posted 23 July 2014 - 01:12 PM

Baud rate or setting mismatch was my first thought.  I have verified 9600, 8, none, 1.  I was not aware of com1 issues while debugging so ran another test without the debugger attached.  I have even tried running on com2 without good results.  A colleague is also doing some dev and is seeing the same issue with his device.  These are new devices we just received within the last week.



#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 23 July 2014 - 01:32 PM

What cable do you use to connect Netduino Plus 2 to the PC? Could it be faulty (e.g. cheap USB converter)?
 
Also, does the data table in your original message mean that Netduino receives character with ASCII value 6 for the original '0' character, ASCII 103 for '1' etc.? If not, what data are you sending?



#5 jonlf

jonlf

    New Member

  • Members
  • Pip
  • 4 posts

Posted 23 July 2014 - 01:38 PM

I am connecting the RS232 port (5V) from my PC using pins 2,3 and 5 to the appropriate pins of the UART on the netduino.  There is no converter cable being used.  Regarding the table, the first column represents the character I sent to the netduino, the second column represent the char code (ASCII) the netduino "sees" or spits back.  I have since modified the code to echo back the character it receives and I get improperly translated characters as I would expect based on the table provided.



#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 23 July 2014 - 01:48 PM

Are you sure the RS232 port on your PC is 5V? Usually, they are standard 12V; and "5V" RS232 can also mean 5V (and not 0 - 5V). Netduino has 3.3V logic (inputs in digital mode are 5V tolerant), so you'd need a level converter to connect it to PC.



#7 Spiked

Spiked

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 23 July 2014 - 02:40 PM

If it also fails on com2, it almost certainly would be an electrical problem to me, as CW2 suggests. I suspect many of us do not even have PC's with RS-232 serial ports any longer, I know I do not.

 

Since you and your friend both have Netduinos, a netduino to netduino test might shed some light.



#8 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 23 July 2014 - 07:44 PM

RS232 uses inverted logic; TX/RX idle logic low. Netduino COM ports idle high. Most PC serial ports are RS232 and they may or may not conform to the RS232 standard (+/- 12V). Measure the TX voltage on your PC serial port. If it is less than about 2.5V, then your problem is inverted logic. You can invert TX/RX with a 74LVC2G14 or a 74HC14 Schmitt trigger Inverter The simplest thing to do is just buy a USB to serial TTL adapter and forget the PC serial port.
 



#9 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 27 July 2014 - 03:12 AM

You need an rs232 shield.  You can't directly plug into the serial port due to voltages or some such.  I tried something similar, and went through the same pain of not understanding why.  Fortunately, the shield is only $12, so it's not a killer.  And you don't have to change any code at all.

 

I would paste a url to the shield, but this forum software won't let copy and paste work in Internet Explorer.  I've posted about this before but nothing has been done to fix it.  Just search for cutedigi rs232 shield for arduino.  Either v1 or v2 will work for you.

 

Hope this helps.



#10 jonlf

jonlf

    New Member

  • Members
  • Pip
  • 4 posts

Posted 01 August 2014 - 09:14 PM   Best Answer

Boy do I feel stupid.  It was a line level issue.  Thanks for the second set of eyes on something I should have known to look at more closely.







Also tagged with one or more of these keywords: UART

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.