println() function doesn't return Max485 to listening mode
k4kfh opened this issue · comments
For me your "echo" example only partially works. I am using a MAX485 chip (not a module, just the DIP IC) wired up with a 120 ohm resistor between A/B. I can get messages from the Arduino on my PC, but I can't get the Arduino to echo back a message sent from my PC.
Edit: After poking around with the oscilloscope, it seems that the println
function that says "hello world" at the beginning of the sketch is the culprit. Once that runs, the TX/RX control pin never returns to LOW, so the MAX485 stays in TX mode forever until you call set_mode(Auto485::RX)
manually. Adding set_mode(Auto485::RX)
after the initial println()
call solves everything and the sketch works perfectly.
It seems you didn't implement all the possible versions of the println
function. You only redefined println(void)
, so all the other ones were just inherited from the Print
class, meaning they didn't call set_mode(RX)
. After adding all the other function types to the library, the example works as expected.
I've added a pull request with the fix for this issue.
Thanks for investigating this. It's odd though, all the other println(...)
methods call println(void)
(e.g. hardware/arduino/avr/cores/arduino/Print.cpp#L117) so I would've thought I could just override that one method?
However if this is what is needed to fix it, who am I to argue :) Nicely implemented too, cheers.