Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xenon: Serial/Serial1 missing bytes #1955

Open
jaredwolff opened this issue Nov 4, 2019 · 9 comments

Comments

@jaredwolff
Copy link

@jaredwolff jaredwolff commented Nov 4, 2019

Bug Report

When trying to run a simple command/response protocol with a separate device using Serial1, I've run into some issues when Serial as a debug mechanism.

Expected Behavior

When connected to the device using the VCP, (9600 BAUD) a single byte 0x03 is issued over Serial. That gets forwarded on to Serial1. A response from Serial1 is then forwarded on to Serial. A response should be that byte 0x03 plus an additional 3 (usually 0x00). No matter how many times the command is sent.

Observed Behavior

When sending, some bytes are missed on the return. See below:

Screen Shot 2019-11-03 at 9 15 34 PM

Steps to Reproduce

I used two Xenons in Manual mode. DeviceOS 1.4.2. I also went back and tried on an earlier version (1.3.1) but no change.

Test App

The Device Connected via VCP

// setup() runs once, when the device is first turned on.
void setup() {

  Serial.begin();
  Serial1.begin(9600);

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {

  // Process from PC
  while(Serial.available()) {
    char c = Serial.read();
    Serial1.write(c);
  }

  // Echo on the other end.
  while(Serial1.available()) {
    char c = Serial1.read();
    Serial.write(c);
    // Serial1.write(c);
    // Serial1.write((uint8_t)0);
    // Serial1.write((uint8_t)0);
    // Serial1.write((uint8_t)0);
  }

}
}

void loop() {

}

The "Remote" Device

// setup() runs once, when the device is first turned on.
void setup() {

  Serial.begin();
  Serial1.begin(9600);

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {

  // Process from PC
  // while(Serial.available()) {
  //   char c = Serial.read();
  //   Serial1.write(c);
  // }

  // Echo on the other end.
  while(Serial1.available()) {
    char c = Serial1.read();
    // Serial.write(c);
    Serial1.write(c);
    Serial1.write((uint8_t)0);
    Serial1.write((uint8_t)0);
    Serial1.write((uint8_t)0);
  }

}

References

Community forum post.

@jaredwolff

This comment has been minimized.

Copy link
Author

@jaredwolff jaredwolff commented Nov 4, 2019

It also seems like the buffer is not being utilized. Serial1.available() returns 1 even if I haven't read bytes. Even if there are several bytes to be received.

@jaredwolff

This comment has been minimized.

Copy link
Author

@jaredwolff jaredwolff commented Nov 4, 2019

Even removed Serial from the whole equation. Using the debugger Serial1.available() returns > 1 but the buffer doesn't accumulate. It seems to reset.

bool sendByte = false;
int  bytes = 0;

void send() {
  sendByte = true;
}

Timer timer(1000, send);
// setup() runs once, when the device is first turned on.
void setup() {

  // Serial.begin();
  Serial1.begin(9600);
  timer.start();

  pinMode(D7,OUTPUT);

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {

  if( sendByte ) {
    sendByte = false;
    Serial1.write(3);
  }

  // Echo on the other end.
  if(bytes = Serial1.available()) {
    if(digitalRead(D7)) {
      digitalWrite(D7,LOW);
    } else {
      digitalWrite(D7,HIGH);
    }
  }

}
@jaredwolff

This comment has been minimized.

Copy link
Author

@jaredwolff jaredwolff commented Nov 4, 2019

Here's the test setup:

IMG_4042

@Cheong2K

This comment has been minimized.

Copy link
Contributor

@Cheong2K Cheong2K commented Nov 4, 2019

Hi @jaredwolff, we are looking into this issue, we will get back to you as soon as possible.

@Cheong2K

This comment has been minimized.

Copy link
Contributor

@Cheong2K Cheong2K commented Nov 6, 2019

@jaredwolff, have you got this resolved? I could not replicate this issue with my units so far.

@jaredwolff

This comment has been minimized.

Copy link
Author

@jaredwolff jaredwolff commented Nov 6, 2019

Nope. I only made this ticket after many attempts of fixing it. Can you describe your test setup so I can try to replicate it working on your end?

@Cheong2K

This comment has been minimized.

Copy link
Contributor

@Cheong2K Cheong2K commented Nov 6, 2019

My setup is exactly the same as yours with the code you provided. I tried with manual mode as you said, also I tried with system thread enabled, I sent from my PC every 1ms, it works for me.

Would you mind to check again with the GND wire or change the wires with another set to see?

@jaredwolff

This comment has been minimized.

Copy link
Author

@jaredwolff jaredwolff commented Nov 6, 2019

Did you use the first set of code? The only way I got it to happen was by sending 0x03 manually as fast as I could click the mouse using Cool Term.

As mentioned the signal looked ok even when some bytes were missing. So is it possible ‘Serial’ is dropping those bytes?

The second set of code was removing that element. I.e. it’s not the failure case. What I did see was Serial.available() not incrementing as more bytes are received and not read. Is this expected?

@ScruffR

This comment has been minimized.

Copy link
Contributor

@ScruffR ScruffR commented Nov 8, 2019

I also found some odd behaviour where the first byte transferred always seems a bit off
image

This is the trace created by this code (on Argon 1.4.2)

SYSTEM_THREAD(ENABLED)

uint8_t data[4] = { 0x00, 0x00, 0x00, 0x00 };
void setup() {
  Serial1.begin(250000, SERIAL_8N1);
}
void loop() {
  Serial1.write(data, sizeof(data));
  delay(1000);
}

Note the extended stop bit of the initial byte.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.