Mega to RS485 UART - Enable Pin Set High However Randomly Goes and Stays Low


i 1 step above newbie using mega's serial1 hardware communicate controller (pic18f) communicates via rs485 half-duplex.  using external max485 connected mega 3 wires, 2 serial1 rx , tx , third digital pin (i use mega 7) toggle max485 "enable" pins (2 , 3 tied together). when enable pin low(default) max485 "receiver output" pin 1 able send mega whatever receiving on rs485 bus line.  when want transmit mega max485, need set max485 "enable" pins high toggles max485 "driver input" (pin 4) accept input mega.

my basic sketch sends constant 5 byte data packet mega max485 every 200msecs , works fine of time except out of blue stops working or never starts.  have checked 10x high impedance scope probe, , max485 enable pins low instead of high nothing gets onto rs485 bus a-b lines.  make sure mega digital pin driving max485 enable not floating have tied mega pin (7) vcc rail 10k resistor has not helped.

simplify problem, took pic18 device out of picture completely.   instead have taken max485 , b bus , tied these both gnd via 360 ohm resistors. problem still persists.

i have tried both genuine arduinomega (vcc 5v) max485 (vcc 5v) , used moteinomega (vcc 3.3v) max3485 (vcc 3.3v) , find same odd random behavior.  replace breadboard , jumper pins hardwired versions on veroboard , same behavior.  can make failure toggle max485 enable pin more frequent touching agilent scope tip mega tx line (not rx) or mega pin being used toggle max485 enable.

the baud rate slow @ 9600 , cannot change pic18f device communicating proprietary , runs 9600. 

i have been told sounds stray capacitance on mega pin used toggling max.  more can in final design prevent this?  add bypass cap gnd?

i pretty sure once put of project box and  keep hands , probes away work fine.  seems sensitive problem such basic use of arduino mega.

here basic code using:
code: [select]


#define rs485transmit    high
#define rs485receive     low

byte receivepacket [5]; 
int max485_control = 7;  //for max485 set high enable arduino tx input max485

void setup (){
  serial.begin (9600);
  serial1.begin (9600);
  pinmode(max485_control, output);  // set max485 rx or tx
  digitalwrite(max485_control, low);    // sets re low on max485 (rx enabled &tx disabled)
  delay(1);  // give max time set tristate
}

void loop (){
  checkserial();
  }

void checkserial()
{

  receivepacket[0] = 2;
  receivepacket[1] = 136;
  receivepacket[2] = 49;
  receivepacket[3] = 0;
  receivepacket[4] = 4;
 
  sendserial();*/
}

void sendserial()
{
  digitalwrite(max485_control, high);   
  delay(1);
  serial.println("tx= ");
  (int j=0; j < 5; j++)
  {
    serial1.write(receivepacket[j]);
    serial.print(receivepacket[j]);
    serial.println(" ");
  }
digitalwrite(max485_control, low);    // sets re low receive again
}


some quick observations.
-add decoupling caps on vcc pins of: both max485 , pic. (pic18f uses it's own max485 or transceptor?)
-let enable pin (pin 7 right?) without pull-up, once it's set output there no need that.
-did connect both grounds (mega , pic) together?
-i've read , proved rs485 lines work better 2 120 ohm resistor between , b, 1 @ beggining ,  another @ end of rs485 net.


Arduino Forum > Using Arduino > General Electronics > Mega to RS485 UART - Enable Pin Set High However Randomly Goes and Stays Low


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support