Serial issues/failures

This forum is not working - it hangs when I try and reply, etc. webmastermaster emailed…
So this is a repeat entry but new sketch and problem description.
Mega 2560, latest IDE (Beta). Using #include <SoftwareSerial.h>
I have hard loopbacks (simply wires) on Tx1 to Rx1, Tx2 to Rx2, Tx3 to Rx3 and pins 52 to pin 53.
I am trying to use pins 52 and 53 for serial i/o (PLEASE do not ask why!)
The following sketch does very weird things!
The sketch accepts values of ‘1’, ‘2’, ,‘3’ and ‘l’ (letter l as in loop)
I get very strange results. Best is to try it and see. In short, it seems like entering ‘1’ gets me .available for Serial1, Serial2, Serial3 and same for entering 2 and 3!!! And NO input on pin 52 ever. In short, I have NEVER been able to get any sketch to work with SoftwareSerial on the MEGA…this sketch just demonstrates some way weird things that I have seen. I have been working on this for weeks and at this time, no idea what mistakes I might be making!!!

Again, I apologize for this semi-double posting and because of an apparent forum hiccup, I cannot reply to anything…I get a hung forum condition - no idea why - arduino webmaster (or who ever) has been notified. Please do not reply to this unless you have some meaningful solution or find some incorrect code in my sketch and PLEASE do not ask why I’m using SoftwareSerial.h (unless it simply won’t work and is faulty…)
Thanks,
Geoana

Serial.ino (3.12 KB)

Sometimes the forum is not working very well. I wait a few hours and try again.

I did not check your sketch, but at the first glance I noticed a few things.

Pin 52 and 53 are the SPI interface. You do #include <SPI.h>, so perhaps you use it or used it ? Please remove the #include <SPI.h>

In ‘C’ and C++, this is wrong: if (serialData = ‘l’)
It should be with double ‘=’, like this: if (serialData == ‘1’)

Please use the character ‘one’ in the if-statement. That is, if you want to check for the character ‘one’. You have the letter ‘l’ now (lower-case ‘L’).
if (serialData == ‘1’) // Please retype the ‘1’ to make it a ‘one’.

When you delay, you are not checking for incoming data during that delay. The Serial library has internal buffers, and they could overflow.

When you check the inputs, you check the “available()” function, but after that you read 10 characters. However, you should only read the number of characters that are available.
You can do it like this, as long as you know that only the first or the first few characters are valid and the rest is not. But that is bad programming.

I hope this helps. You have some rewriting to do. If you don’t know how to fix it, just ask.

Thanks! The =/== is the big problem why it seemed like I was getting multiple replies. I program in many languages . . sometimes mistakes happen. In C/C++ i almost always forget the semi-colon first compile! VB6 has no terminating character....one of my favorite languages. ...which MS no longer supports. I have 1000's of lines of VB6 code in many applications that are used today.

Regarding the '1' and 'l' - yes, that was a dumb choice - the original test case I used the l ('ell') for loop_back_test - in this sketch I use BOTH 1 and l (Serial1.)- probably stupidly . . confusing to say the least. SPI - yeah, this is a WAY cut-down script that was originally for the UNO and in fact had multiple serial interfaces and Adafruit's SD shield.....so there is some left over code......delays also being sorta one of them.....The code worked great on the UNO BUT-BUT-BUT ran out of sram!!! I thought that the MEGA was a drop-in replacement for the UNO - NOT, apparently.

BUT the result is that I CANNOT get ANY (non-Tx1.2.3) pins to work with the SOFTWARESERIAL library. Transmit works fine (o'scope verification) but looping back with a wire or using the devices that I want to really use gets me NO inputs. And of course, the old o'scope shows them transmitting to the Rx pins. I chose 52/53 as they seemed to be 'acceptable' pins in Arduino write-ups for the MEGA (input interrupt issues).

Oh yeah, and the 'forum' now works great - switching from IE to Chrome seems to have fixed all.....Arduino webmaster sent me an email (as I think I said) that IE and the forum has unresolved issues!

Oh yeah, and I went to the BETA IDE from the regular release to see if that might help with the inability to get any Rx pins to work with SOFTWARESERIAL.h . . . George

Are you using this cut-down sketch to test ? You can not use the SD card (SPI interface) and also pin 52 and 53 for something else. There are still 16 other pins you can choose from. http://arduino.cc/en/Reference/SoftwareSerial

I checked the sketch once more, but I can't find the problem. You can remove these in setup():

pinMode(SL_RX_Pin,INPUT);
pinMode(SL_TX_Pin,OUTPUT);

You do that after the SoftwareSerial class has initialized and before SoftwareSerial.begin(), but they are not needed.

You also do a read() when there could be nothing available(). Maybe you hit a bug by doing that.

If you have another Arduino board, you can do the most simple test there is. Let the other generate a few characters per second, and let the Arduino Mega with SoftwareSerial echo the incoming to the serial monitor on the computer.

You can try the https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html by Paul Stoffregen. You must use pin 46 and 48. Maybe you can try this right now: make a small test sketch and see what happens. If it works, there is not need to go back to SoftwareSerial, since the AltSoftSerial is just as good (or better).