Doesn't work when Arduino power on while receiving RS232

Hi I am kino.

When a specific word is received through RS232 communication, it responds to it.

After applying power, RS232 communication works normally.

If apply power after connecting RS232 communication, Arduino is the same as stopping.

Any help would be appreciated.

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27 ,20,4);

​

void setup() { 

  Wire.begin();

  Serial.begin(9600);

  Serial.setTimeout(100); 

  

  lcd.init();                    

  lcd.backlight();       

}

​

void loop() {

  clcd_display();  

  RS232_PC2();  

}

​

​

void clcd_display (){

    lcd.setCursor(4,0);          

    lcd.print("   Running   ");

}

​

void RS232_PC2(){

  String inputStr;

  if(Serial.available())

  {

    inputStr = Serial.readStringUntil('\r'); 

  }

  

  if (inputStr == "A") {

   Serial.println("A");

  }

  Serial.flush();

}

Check your RS-232 hardware. It should be hot-plugable, i.e. connect and disconnect is allowed all the time.

You need to be specific what does "it" refer to?

Is it the Arduino or an external part of the circuit?

Are you saying the LCD does not function if the Arduino is started after the LCD.

The easiest answer would be to have a timed startup of external devices so that they all started after the arduino.

Information is key to answering a question, if it is the LCD, which LCD is it? Describe external device/s connected to serial.

Arduino itself freezes.
It's the same if I remove everything about the LCD.

--------example---------------

void setup() { 
  Serial.begin(9600);
  Serial.setTimeout(100);    
}

void loop() {
  RS232_PC2();   
}

void RS232_PC2(){
  String inputStr;
  if(Serial.available())
  {
    inputStr = Serial.readStringUntil('\r'); 
  }
  
  if (inputStr == "A") {
   Serial.println("A");
  }
  Serial.flush();
}

If I connect the communication after uploading the code, there is no problem.

In RS232 communication, if the power is OFF -> ON in the state of asking A, the Arduino MEGA does not operate.

You need to give details about which LCD you are using and a circuit diagram/schematic.

What do you do if this returns ZERO bytes available? Perhaps change to if(Serial.available() > 0).

Which RS232 signal level adapter do you have (post a link)?

Also post a wiring diagram showing how is it connected to the Arduino. Hand drawn is fine.

Please edit your post to add code tags ("< code >" editor button).

make sure DTR is not low..
USB port typically disappears when unplugged..
curious, how you opened a non-existent port..
reset button is tied to DTR, bring DTR low/high will reset mega..
half a second it waits for sketch upload then already loaded sketch begins..

good luck.. ~q

image

I use DTR when uploading, but that doesn't seem to solve the problem.
First of all, it seems that the problem is that the device continues to send data, and the Arduino is turned off, but it seems to be freezing because the buffer is full.

The Arduino will not function properly and can even be destroyed, if it is powered down with 5V applied (from an external source) to any of the input pins.

It that is happening with the MAX232, add a 10K resistor in series with MAX232 TX to Arduino RX connection, to limit the current flow through the input protection diode.

Additional information.

  1. Normal operation

  • Check RS232 Communication

  1. Power off

  1. Power on

Cable : USB to RS232 ( NETmate USB2.0 to RS232)
RS232 module : Manufacturing: YwRobot ( RS232 - TTL Module [MCU030310])

LCD : 2004 LCD(I2C Control.)

try using pin 18 and 19 and change Serial to Serial1..
Serial "0" is used for downloading sketches..
functions/communication/serial
kind of warn us not to use those ports and that mega has 4 in total..
use Serial for debugging when usb is plugged in and all the others for what ever..
look at how i did AckMe..
good luck.. ~q

This is why a schematic and photo of your setup is key to the answers you get.

The USB will power up the interface then put the serial Voltage onto the Arduino pins.

The easiest fix for this is to have a data only USB cable, then connect the power from the Arduino to the Max232 board, via an RC time delay. Time delay just needs to be long enough for the Arduino to start.

I have a similar problem with my 3D printer, which has a serial communication with a RasberryPi, easily solved by having the whole lot on the same supply switch, the printer firmware starts before the Pi has finished booting, thus avoiding the seial setup problem.

qubits-us Thanks for that info, nice to know for future reference.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.