chipKIT® Development Platform

Inspired by Arduino™

Really strange and weird problem about UART Serial.Read() :(

Created Thu, 25 Dec 2014 19:42:52 +0000 by devrirobotik


devrirobotik

Thu, 25 Dec 2014 19:42:52 +0000

It is a really weird problem. I am using Serial Port 4. I mean U5. (I activated it on libraries.)

And my code is the simplest MultiSerial code. (Serial4->Serial and Serial->Serial4)

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial4.available()) {
    int inByte = Serial4.read();
    Serial.write(inByte); 
  } if (Serial.available()) {
    int inByte = Serial.read();
    Serial4.write(inByte); 
  }
}

And my library is the simple library (that without the interrupt function.)

And sometimes It works properly.

But many times It gives different characters.

(By the way I used all the baudrates and It is definitely not a Serial.Write problem. I am positive it is a Serial.read problem)

For example:

$VNINS,$VNI,$VNIN...

or

$VNIdgsgsglgkchnlskfjg(weird charactes)VNIdgsdfgdf$VNalgfkdsjg

or

$VNINS,0035(null)(null)(null)(null)(null)(null) (I mean it gives 0xFFs.. )

and so on....

but It should give: $VNINS,,333811.902862,1694,0004,+009.500,-004.754,-000.225,+32.95602815,- 096.71424297,+00171.195,-000.840,-000.396,-000.109,07.8,01.6,0.23*5F

I really dont understand the problem. :S:S

I checked the input and output pins with some logic analyzer many times and there's nothing wrong on hardware side.

I don't know what should I do :S

Thank you so much for your helps..


Jacob Christ

Fri, 26 Dec 2014 17:19:03 +0000

Sounds like software timing issue.

I don't think this is related but why do you do Serial1.begin(9600) in setup() and not Serial4.begin(9600)?

Jacob