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

Issues with COM1 through RS485 shield


  • Please log in to reply
6 replies to this topic

#1 Cinelli

Cinelli

    Member

  • Members
  • PipPip
  • 17 posts

Posted 27 June 2011 - 09:47 PM

Hi, we are working with RS485 shields. Correct me if I'm wrong but it appears COM1 is routed through analog pins 0 & 1 TX/RX. This is just to do something we had running previously on other .Net MF platforms with no issues. We set up the COM port, added 5 seconds extra wait time to fill the COM buffer, and then read the whole buffer. The buffer only contains some of the bytes, so partial data received. We are using the Microsoft.SPOT.Hardware.SerialPort library (I assume Netduino uses this also). Can you link or paste in sample code for setting up the COM port (4.1 or 4.2)? We would like to assure we are doing this right. We did it in 2.5, then made the switch to the new 3.5+ COM port setup. The same shield (physically the same one, not just the same type) worked in another Arduino-format application, so it's unlikely to be the hardware. TIA.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 27 June 2011 - 11:06 PM

Hi Cinelli, Are you using analog pins 0/1 or digital pins 0/1? The serial ports are D0/D1 (COM1) and D2/D3 (COM2). Chris

#3 Cinelli

Cinelli

    Member

  • Members
  • PipPip
  • 17 posts

Posted 28 June 2011 - 05:28 AM

Sorry, I did mean the Digital pins. Refernce this shield though we use others also: http://tinyurl.com/3hodmg2 Thanks Chris, love the Netduino project and Secret Labs hardware.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 June 2011 - 06:32 AM

Okay it looks like you're using the right pins. Can you post a small snippet of your old and new code? The new code should look pretty much like the .NET (desktop) way of doing things. Chris

#5 Luca Monaco

Luca Monaco

    New Member

  • Members
  • Pip
  • 3 posts

Posted 18 July 2011 - 03:22 PM

Sorry, I did mean the Digital pins. Refernce this shield though we use others also:
http://tinyurl.com/3hodmg2

Thanks Chris, love the Netduino project and Secret Labs hardware.

Hi Cinelli,
I am very interested to this shield, but I never used it.
In shield documentation they said:
"The chip's DE (output enable) pin (3) is connected (via a resistor) to the Arduino's Digital Pin 2 - this is active high.
This DE pin is also connected to the chip's RE bar (receiver enable) pin (2) and therefore controlled by the Arduino's Digital pin 2 too - this is active low.
Arduino Digital Pin 2 = Rx/Tx 'Enable'; High to Transmit, Low to Receive"


So you have use also the Digital Pin 2.
Set it to true before trasmit data,
Set it to false after tasmitted data.

Let us know if it works.

#6 rht

rht

    Member

  • Members
  • PipPip
  • 15 posts

Posted 04 September 2013 - 08:26 PM

Hi, it looks like we are running into this or a similar problem with the http://linksprite.co...eld_for_Arduino shield. Can anybody provide more information or code? We've tested our code using an emulator and the rs485 device coms as well. The shield blips once TX but never receives a RX. Not sure yet how to debug this further. Any tips appreciated. 

Thanks!

GG



#7 pvanroos

pvanroos

    New Member

  • Members
  • Pip
  • 3 posts

Posted 24 October 2014 - 10:59 PM

Hi all,

 

Did anyone ever figure this out?  I've got a RS-485 Shield from LinkSprite and I can't get it work.  Here are some details from my project:

 

1. Linksprite RS-485 Shield V2.1 - http://linksprite.co...2.1_for_Arduino

2. Using SerialPort for communication:  http://msdn.microsof...y/ee432679.aspx

3. Communicating over CAT6 twisted pair to a device at other end expecting 9600 baud, Even parity, 7 character bits, and one stop bit.

4. Twisted pair inserted into H2 485-A and 485-B ports.

5. Netduino Plus 2 (bought a month ago with no firmware updates)

6. Set to 5V using jumper.

7. Set to D0 and D1 using jumper.

8. Set to TX_CTRL using jumper.

9. Plugged into computer to deploy code.  Headers are not soldered but they fairly snug and not loose.

10: Code:

        static SerialPort serial;
        static OutputPort led;
        const int bufferMax = 10000;
        static byte[] buffer = new byte[bufferMax];
        static int bufferLength = 0;

        public static void Main()
        {         
            led = new OutputPort(Pins.ONBOARD_LED, false);
            serial = new SerialPort(SerialPorts.COM1, 9600, Parity.Even, 7, StopBits.One);
            serial.ReadTimeout = 1000;      
            serial.DataReceived += serial_DataReceived;
            serial.ErrorReceived += serial_ErrorReceived;
            serial.Open();

            while (true)
            {
                {
                    led.Write(true);
                   
                    Debug.Print("Request sent");
                    string hexrequest = "2F3F3030303330303030313039363030210D0A";
                
                    // Create request
                    byte[] seq = StringToByteArray(hexrequest);

                    if (serial.CanWrite)
                        serial.Write(seq, 0, seq.Length);    
                                           
                    led.Write(false);
                }

                string line = "> ";

                for (int i = 0; i < bufferLength; i++)
                {
                    line += buffer[i] + ",";
                }

                Debug.Print(line);
                if(serial.IsOpen) Debug.Print("Port is open.");
                Thread.Sleep(10000);
            }
        }
        static void serial_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
        {
            if (e.EventType == SerialError.TXFull)
            {
                Debug.Print("Error:  TXFull");
            }
            else if (e.EventType == SerialError.RXParity)
            {
                Debug.Print("Error:  RXParity");
            }
            else
            {
                Debug.Print("Error:  Some other error");
            }
        }

        static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {

            Debug.Print(dataRecLineNumber + ": Data received ******* - " + t );
       
            int bytesReceived = serial.Read(buffer, bufferLength, bufferMax - bufferLength);
            if (bytesReceived > 0)
            {
                bufferLength += bytesReceived;
                if (bufferLength >= bufferMax)
                    throw new ApplicationException("Buffer Overflow.  Send shorter lines or increase lineBufferMax.");
            }
        }






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.