Serial Communication Woes with Mega 2560

Hello,

I am using a Mega 2560 for a nuclear physics experiment. My plan is to place the Mega at the high-voltage terminal inside of a tandem accelerator to control a gas system, and interface this Mega with LabVIEW via optical fiber links. When I run the experiment, the Mega will turn on when the charging chain inside the accelerator is activated. I will then establish serial communication with the Mega. My entire scheme is as follows:

LabVIEW ----- RS232 ---- Fiber Optic Conversion --------- RS232 ------ TTL Conversion ------ Mega

My problem here is that in bench-top testing, if I turn on the Mega under any circumstances except when I have it connected by USB to a computer running the Arduino IDE and "serial monitor," any code related to serial communication does not seem to run. I have tested the functionality with a simple sketch:

void startup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println("Alive");
delay(1000);
}

After uploading this sketch, I will see the appropriate message sent to the serial monitor if it is open, and see the TX light blink periodically. If I reset the Arduino without the serial monitor open, then I do not see any any blinking of the TX light. In some cases, the rest of my code will run; in others, it will not. I am hoping to find a robust solution, because the Mega will be entirely inaccessible after it has been installed in the tandem.

Thanks very much for any help,

Will

There are many places in your serial data chain where a reversed tx and rx could be causing your bits to go in the bucket.

Can you confirm how far the tx data gets from the arduino using a scope (or even an LED with a resistor)?

Alternatively, is it possible to do a loopback check from lab view? Check successive steps in the link to confirm function...

-br

Thanks for the reply bilroy,

In the simple test case I've described, I haven't actually implemented any of the chain. I included a description just in case it would be helpful to know the context. With the simple sketch I've described, I've only connected the Mega to an external power supply, and left the TX/RX unconnected. Should I not expect the serial communication to initialize when the TX and RX are left unconnected?

LundenWill:
If I reset the Arduino without the serial monitor open, then I do not see any any blinking of the TX light.

As I recall, the Rx and Tx lights are on the USB interface chip, not the Atmega2560 chip. Thus, with no USB connection they may well not flash.

In some cases, the rest of my code will run; in others, it will not.

What code? How do you know? What you have posted there is no more code.

The Tx and Rx pins on the processor itself should work reliably. You could hook up an LED (and resistor) yourself to check that.

If things are not reliable there may be other issues such as coding problems, or electrical problems.

Typically trying to wire an led/resistor on pin 0 can be problematic when it's an input pin (as during serial communications) as the series 1k resistor from the serial USB chip will form a voltage divider with the led/resistor. Monitoring pin 1 with an led/resistor should work OK.

Lefty

If you are doing nuclear physics hopefully your budget would run to a logic analyzer. That will tell you exactly what is happening. I use the Saleae one:

Only $149.

Thanks for the replies,

If I understand correctly, then the TX and RX pins can be working perfectly correctly even if I do not see the respective SM LEDs flashing? I will certainly try looking at Pin 1 with an LED + resistor in the morning.

As for the "other code" I've mentioned, I have sometimes included a pin 13 "blink" as a heartbeat to see that the board is functioning. In most cases, this blink will occur after I connect the board to the external power supply. In a few cases, the board simply held the pin 13 LED lit indefinitely, but I suspect that this problem was related to some out-of-date drivers. I thought I'd mention this in case it were relevant.

The logic analyzer sure looks appealing, and perhaps would be a useful tool to have in the lab...

Extremely useful. Of all the test equipment I have that is the one I use the most often. Second would be a good multimeter.

As for the heartbeat, it's a good idea to have it, you may have other issues like using the String class, memory overflow, array out of bounds, interrupts not being processed correctly, etc.