Skip to content

Mega 2560 Serial1, Hang on HardwareSerial::flush() #281

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

Open
AliShug opened this issue Aug 1, 2016 · 0 comments
Open

Mega 2560 Serial1, Hang on HardwareSerial::flush() #281

AliShug opened this issue Aug 1, 2016 · 0 comments

Comments

@AliShug
Copy link

AliShug commented Aug 1, 2016

This is probably (?) related to previous issue arduino/Arduino#1742, but happens with 1.6.8. I'm running some Dynamixel smart servos from the hardware serial ports on the board; AX-12As off Serial0, and XL-320s off Serial1. As far as I can tell the hang isn't happening on Serial0, although obviously the two ports are being used slightly differently. Both are run at 1000000 baud.

Basically, everything will be fine for anywhere between 2-20s, but once the hang is triggered the board is completely unresponsive until power off/on or serial reset (reset button does nothing). I've got a logic analyser hooked up, and the final packet on the serial line is always sent in full. Control just doesn't make it past the subsequent flush(). Code looks like this:

// Write out the buffered packet
for (int i = 0; i < _packet_length + 7; i++) {
    unsigned char b = _packet_data[i];
    Serial1.write(b);
}

// Ensure output completed before we switch comm modes
Serial1.flush();
digitalWrite(CommPin, 0);

That CommPin line stays HIGH for the rest of time. Replacing the flush() with a bunch of asm nops (to delay for a microsecond or three) works without issue.

@sandeepmistry sandeepmistry transferred this issue from arduino/Arduino Sep 16, 2019
@sandeepmistry sandeepmistry transferred this issue from arduino/ArduinoCore-API Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant