Author Topic: SoftwareSerial - MoteinoMEGA [FIXED]  (Read 5381 times)

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
SoftwareSerial - MoteinoMEGA [FIXED]
« on: March 05, 2016, 01:54:24 PM »
Several times I have attempted to utilize the Arduino SoftwareSerial library (for various hardware comms).  Each time I haven't been able to figure out how to make the MoteinoMEGA receive data (I hadn't even bothered with testing to send, yet), and had to revert to using Serial1.  Now I need a 3rd serial port.

For the hardware which I intend to communicate with via SoftwareSerial, I have tested sending/receiving using Serial1 port.  All good there.

During my testing of SoftwareSerial I have been using pin 1 for TX (theoretically it shouldn't matter if the pin is interrupt capable or not), for RX I have used pins:
3, 10, 11, 31
Pins 10 and 11 are interrupt capable and thought I might be able to use both for RX for different hardware (with separate TX pins).

FYI: there is a transceiver on the Moteino.

Does anyone have any thoughts?

Cheers,
Chris
« Last Edit: August 24, 2016, 08:19:00 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: SoftwareSerial - MoteinoMEGA
« Reply #1 on: March 05, 2016, 11:38:12 PM »
Chris,
First, pins 10 & 11 are hardware Serial1.
There is no pin 31.
Did  you try any other pair, say something like 18-19 or 13-14?
Have you verified your wiring is correct (tx goes to rx etc)?

UPDATE:The issues and solution are explained in this post.
« Last Edit: August 24, 2016, 08:19:09 PM by Felix »

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
Re: SoftwareSerial - MoteinoMEGA
« Reply #2 on: March 07, 2016, 01:28:21 AM »
Hi Felix,

First, thanks for your reply.

Yes, pins 10/11 are Serial1, which I used for testing to ensure the wiring correct between Moteino and the serial hardware.  Communication is perfect between the Moteino and the serial hardware when connected to Serial1.
Pin 31 (D31) is the A7 pin.  (I'm aware that's an analog pin)
The pin pairs I tested were:
0-1
0-3
1-3
1-10
1-11
1-31

Since posting the question, I have:
1) Verified that data transmit works (from Moteino) using pin 1 for TX.
2) Tried using EnableInterrupt library, which shouldn't be necessary since SoftwareSerial performs the function of enabling interrupts.  No success.
3) Created a test sketch, using digitalPinToPCICR, that reports which pins can enable interrupt function (PCINT). It reported all digital pins do support interrupts, but not any of the analog pins.
4) Used example sketch Mighty1284p and verified it sees an RX interrupt while using pins 1 or 3 as RX pin.

Thanks again for your thoughts.

Chris

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: SoftwareSerial - MoteinoMEGA
« Reply #3 on: March 07, 2016, 08:03:04 AM »
I think you lost me. Initially I thought you were having trouble with software serial (using a 3rd serial on MoteinoMEGA as a software serial).
You are talking about software serial an PC interrupts. Sounds like you're trying to detect a serial message using PC interrupts?
What sketches are you referring to?
Yes analog pins can be used as digital pins.

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
Re: SoftwareSerial - MoteinoMEGA
« Reply #4 on: March 07, 2016, 02:06:26 PM »
Hi Felix,

SoftwareSerial library will not work if the chosen RX pin is not PCINT capable.  As such, I needed to verify which pins are PCINT capable on Moteino.

Not sure where I confused you with the sketches.  The Mighty1284p sketch is an example sketch which comes with the EnableInterrupt library, which I used to verify that my wiring is correct and that the Moteino can use pin 3 (or other) as a RX pin for SoftwareSerial.  The Mighty1284p sketch correctly detected RX data on the pins I tested (1 and 3).
The test sketch I created is:
void setup () {
    for (byte p = 0; p < 39; ++p) {
      Serial.print(F("Pin: "));
      Serial.print(p);
      Serial.print(F(" interrupt capable: "));
      Serial.println(digitalPinToPCICR(p) ? "Yes" : "No");
    }
}
void loop () {
}


I hope this clarifies the steps I had taken.


At this point, I'm a bit confused as to why SoftwareSerial doesn't detect incoming data on pin 3, while the Mighty1284p example sketch does.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: SoftwareSerial - MoteinoMEGA
« Reply #5 on: March 07, 2016, 03:12:12 PM »
At this point, I'm a bit confused as to why SoftwareSerial doesn't detect incoming data on pin 3, while the Mighty1284p example sketch does.
Ok, I'm primarily concerned with any hardware issues. If there's a hardware problem let me know but it really sounds like you are having a library/software problem. It's not clear to me what exactly you're trying to do. I am not 100% familiar with all the libraries out there. If a specific library does not work the way you expect it, I would suggest perhaps asking the library creator.
While SoftwareSerial is a good alternative when you have a lack of serial ports, hardware serial is a much better device to use since it's buffered, whereas softwareserial is not and you have to implement your own buffers if the library doesn't do it for you. How you want to combine that with PCINTerrupts I don't know. I have not clue what "Mighty1284p sketch" is.

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
Re: SoftwareSerial - MoteinoMEGA
« Reply #6 on: March 07, 2016, 03:47:41 PM »
Thanks Felix.

I'm starting to believe it's a library issue.  Will try the sketch on Arduino Nano (which I have plenty available) when I have a chance.

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
Re: SoftwareSerial - MoteinoMEGA
« Reply #7 on: March 08, 2016, 05:54:27 AM »
Update:

I have tested the SoftwareSerial library using an Arduino nano, with RX/TX pins set to 4/5.  Communication both direction works as expected.  So, it's at least clear that the library and serial device works with the nano, as well as the wiring between boards being correct.

This means the problem I am having with SoftwareSerial and Moteino is some kind of incompatibility with the library, the Moteino def files or the Moteino hardware itself.
I had a glimmer of a thought that possibly the transceiver tied to the Moteino is somehow causing a conflict.  I have been planning to purchase a couple MoteinoMEGAs without transceiver, but will probably be several weeks before I can do it since my address will be changing soon.  When I receive the new boards I will be able to test the prospect of the transceiver conflict... although I doubt that's the problem.

I spent several hours looking at the code of the SoftwareSerial library.  It does implement buffers as well as enabling/disabling interrupts as appropriate (initialization, handling interrupts, etc.), so there should be no concern about lost data.
Also spent several more hours reviewing Atmel's docs for the 1284p, and comparing interrupt handling with methods implemented in SoftwareSerial.

Has anyone else had any success using the SoftwareSerial library with the MoteinoMEGA (with or without transceiver))?


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: SoftwareSerial - MoteinoMEGA
« Reply #8 on: March 08, 2016, 08:25:18 AM »
If you post a bulletted list of your requirements and goals of this setup, wiring etc, maybe I'll give it a try myself when I get a break.
Is the Arduino Nano 5v or 3.3v?
Are you able to look at the traces using a scope and compare between the nano and MoteinoMEGA?

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
Re: SoftwareSerial - MoteinoMEGA
« Reply #9 on: March 08, 2016, 05:20:04 PM »
The Nano is 5V, and the serial device is 5V.

While writing the previous update, I did have the thought that perhaps a level-shifter is needed between the Moteino 3v and serial device 5v.  But dismissed the thought after reviewing the Atmel docs and verifying the Moteino does see data on the pin (by polling digitalRead(rx_pin) constantly while sending a large file to Moteino, this isn't an accurate test but does indicate data is arriving at the rx_pin).  The idea of needing a level-shifter is further discounted by the fact that data is transmitted from the Moteino to the serial device without missing any bits, so it seems the 2 devices talk well together.  If there were to be any problems with voltage levels, it would be either the 1284p would underdrive the serial device and/or the serial device would overdrive the 1284p.  Overdriving the 1284p is more likely but, according to the Atmel docs, this shouldn't be a concern at 5V.

I had also reduced the baud rate to 9600 (from 57600) between the devices to see if the signals were coming too fast for SoftwareSerial (it was reported to be a problem in the past but supposedly fixed that issue) while running on a 1284p.  The lower baud didn't make a difference.  Also had set the baud rate to 115200 when testing with the Nano, which SerialSoftware had no problems at that rate.

I don't currently own a scope but will borrow a neighbor's tonight.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: SoftwareSerial - MoteinoMEGA
« Reply #10 on: March 08, 2016, 11:08:18 PM »
Ok. So can you confirm at least the SoftwareSerial works (transmit and receive from MoteinoMEGA)?

Chris

  • NewMember
  • *
  • Posts: 8
  • Country: us
Re: SoftwareSerial - MoteinoMEGA
« Reply #11 on: March 23, 2016, 04:48:03 PM »
Sorry for delayed response Felix,

I borrowed the o-scope and could see the data is being passed in and out of the Moteino.  Unfortunately, the SoftwareSerial library and MoteinoMEGA don't play well together, at least for Moteino RX (fairly certain the issue is interrupt detection/handoff between SS library and Moteino).

Instead of spending additional countless hours attempting an analysis of the 1284p interrupt handling (this should work as all other Atmel devices do, according to Atmel docs and specs), I have taken the easier road and sacrificed the least needed serial component from the design, which drops the needed serial ports to 2.  Obviously, not the solution I prefer but at least development can now resume.

As a side note:  Today I ordered some MoteinoMEGAs without radios.  After they arrive I can test the previous thought of the transceiver hardware somehow interfering, although I don't believe it's an issue.

Cheers,
Chris

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: SoftwareSerial - MoteinoMEGA
« Reply #12 on: August 24, 2016, 08:18:34 PM »
UPDATE:The bug/issues and solution are explained in this post.