Multiple Serial Devices and Buffers - Ideas?

I have a 328p-au based design that I have a board built for. 16MHz/5V bootloader installed, it programs fine, runs code properly, serial monitor works, basically it behaves just like an Uno/5V ProMini.

Attached to this micro, I have the following:

  • GPS (via softwareSerial, 9600 Baud only, interfaced via level-shifter)
  • Xbee - S3B 900MHz (via SoftwareSerial, 9600 Baud only, interfaced via level-shifter)
  • Connection to another 328p via SoftwareSerial, currently 38400 Baud but the rate isn't too important

This is actually all I have connected, so most of the pins are being left un-used. The hardware serial port is only connected to an FTDI header so I can use it in the serial monitor.

I can talk to all 3 of the above devices fine using the SoftSerial.listen() command, but obviously I lose any data that comes in on either of the other 2 devices during that process. This isn't really ideal for my uses.

What I really want to be able to do is:

  • Continuously stream the GPS data (ideally at up to the full 10Hz it is capable of, but I could make do with lower rates for now) out of the XBee (to a remote base station). Ideally I would transmit the whole NMEA sentence, but lat/long, and perhaps elevation would be sufficient.
  • Listen for any commands coming in over the XBee from the base station (at the moment, only 1-2 byte commands at infrequent intervals)
  • Relay some of those commands to the attached secondary 328p (which will mostly be busy doing heavy data-logging), and relay through the XBee to base any status commands the attached chip sends back.

So right now, the above is not really possible since there aren't buffers for all 3 devices due to how SoftwareSerial works (or at least how I understand it works).

So I see a few solutions:

  • Drop the 328p in favor of a chip that has more HW serial ports, and thus buffers for all of them. Since these devices are the entire extent of what is hooked up, it seems silly to go to a 2560 or other solution that is in the 100 pin range. I also don't need the extra RAM, flash, etc of the "bigger" boys.
  • Attach a couple of UART<->SPI/I2C chips between the devices and the 328p. This seems like it would take up a decent bit of board space between the chip(s) and the associated circuitry they would need (it looks like many of them need crystals, and perhaps more?). And would it still do what I need (I think so, but don't know what I don't know).
  • It seems that AltSoftSerial doesn't help me since I have 2 devices locked in at 9600 baud (XBee and GPS). And that only gets me 2 of the 3 links I need (I suppose I could potentially free up the HW serial port but I prefer to leave it available for debugging/programming).
  • Some fancy cheating code solution I haven't thought of?

So really I'm looking for suggestions on the best way to proceed. I'm trying to keep board space to a minimum while preserving the functionality I need. I am looking to switch to a 3V system which will free up some room if need be (I think at least this chip in question can go to 3V without issues, not sure about the second 328p on there, testing is in order). Ideally the solution wouldn't add much cost either, I like that the 328p is fairly cheap (~3USD) :slight_smile:

A Teensy 3.1 might fit the spec

nilton61:
A Teensy 3.1 might fit the spec

Interesting. I'd heard of the Teensy but haven't looked in a while, didn't realize they were using ARM now. Looks very similar to a Due in a smaller package and with fewer pins. I'll have to look into how hard it will be to integrate it into a custom board, might be an answer even if it is a lot more power than I need!

Continuously stream the GPS data (ideally at up to the full 10Hz it is capable of, but I could make do with lower rates for now) out of the XBee (to a remote base station). Ideally I would transmit the whole NMEA sentence, but lat/long, and perhaps elevation would be sufficient.

Pay another $13 USD and duplicate the GPS requirement. You are making your life crazy for the price of a half-decent lunch!

Ray

My Projects

Either commit the hardware serial port to one device and use AltSoftSerial for the others or buy a bigger chip. I don't think there are any magic solutions to get more serial ports on a 328. If you don't want to lose the investment you have in custom boards, then just stack 3 of them and divide up the jobs.