repetier / Repetier-Firmware

Firmware for Arduino based RepRap 3D printer.
812 stars 734 forks source link

[Arduino Mega - Repetier] Serial communication problem #296

Open Ecu84 opened 10 years ago

Ecu84 commented 10 years ago

Hi,

I'm trying to modify the repetier soft (running on Arduino Mega) in order to communicate with it through an USB - serial connection. My goal is to be able to send informations to the Arduino Mega from a self-made JAVA soft running on a PC, and also to receive informations from the Arduino Mega.

The JAVA soft serial communication is made with the use of RXTXcomm.jar. I tested the communication (writing and reading) successfully between my JAVA soft and Arduino Mega in which I loaded a test sketch.

BUT, my problem is that this communication is not working with the modified Repetier soft. The only modification I made on the Repetier soft was to add some "RFSERIAL.println("loop\r\n");" lines is the loop function and in other functions called in the loop.

In fact, when I load the Repetier code in the Arduino Mega, I launch the JAVA soft, and during a few seconds the communication works correctly (I can read the informations from Arduino Mega), but at some moment the communication fails, and I only ave senseless characters.

Here is a console example of the JAVA soft reception : probleme_serie_2

As you can see, it seems that there is some problem with the serial communication. Does someone have any idea to solve that problem ?

Ecu

PS : I hope this post respects the forum rules, it's the first time I'm posting here. If something is not clear, please tell it to me.

dewhisna commented 8 years ago

If you keep waiting, does it straighten back out again? The initial connection on most USB driver configurations causes the DTR to cycle when you open the port. The Arduino Mega (and most all of the AVR based Arduinos) have the DTR input tied to the reset pin (used to trigger the bootloader for reprogramming), causing the Arduino to reset whenever you open the port. Typically during that time, if you are monitoring the serial communications, you see garbage like you are showing because for a period of time during the reset, the bootloader is trying to talk. The garbage is especially noticeable if the bootloader is running a different baud rate than your main firmware code is.

After the reset, and after the bootloader gives up and times out, and after the firmware code in the Arduino gets reconfigured correctly, communications should resume back to normal, assuming your baud rate is set correctly. I don't know for certain if that's what you are seeing, but I bet it is, as I see things like that all the time with AVR boards with bootloaders when trying to use communications programs like minicom with them.

Generally the solution is open the port, delay for a brief period, and purge any receive buffers. Sometimes sending a character or two is also needed to get both sides flushed and communicating. If the reset delay and bootloader garbage aren't acceptable, you have two other solutions -- either remove the bootloader from the Mega and do all reflashing via the ISP connector (this will require some configuration changes to make sure it boots directly to the firmware) or remove the capacitor that ties the DTR line to the reset pin so that it doesn't reset the Mega when the serial port is opened (though that will affect your host software ability to reset the firmware during port open, which you'll have to decide if it's a problem for you or not).