I have the following code for a TTL to RS-485 Adapter Module
[...code] digitalWrite(DE_PIN, HIGH); //directional control for adapter Serial2.write(Message, Size); Serial2.flush(); digitalWrite(DE_PIN, LOW); // Set To Recieve Serial2_reading_foo(); [code...]
I've noticed that
DE_PIN does not seem to go
High fast enough before
Serial2.write() executes I confirmed this by adding a small
delay(ms) which made the code function perfectly.
digitalWrite(DE_PIN, HIGH); delay(100); Serial2.write(Message, Size); Serial2.flush(); digitalWrite(DE_PIN, LOW); // Set To Recieve delay(100); Serial2_reading_foo();
Unfortunately, there's pretty much universal agreement that you shouldn't ever use
delay() in programming. Plus doing any kind of wait function here seems to be insensitive to the real problem. Is there a better way to make sure that
DE_PIN==HIGH before the Serial2.write() Function begins?