TinyCircuits Forum

TinyCircuits Products => TinyDuino Processors & TinyShields => Topic started by: Bullwinkle on August 27, 2018, 04:23:56 PM

Title: Serial.read baud-rate issues...
Post by: Bullwinkle on August 27, 2018, 04:23:56 PM
I've been using a TinyDuino setup successfully for quite a while now, with the Arduino Console set to 115200 baud.
I have had NO problems with OUTput spewing lots of data, with no garbled characters.  I recently decided to add code to accept a user (Console Serial) input ("serial number") to be written to EEPROM.  After wasting far too much time trying to figure out why i was reading back GARBAGE from the EEPROM after (supposedly) writing it, I backtracked to the simple loop using Serial.read(), where I built the user-supplied S/N string.   It was GARBAGE.  After lots of Google finger exercises, I found that some people apparently had (output-related) problems with higher baud-rates; but not much discussion of INput scenarios.  But I decided to try knocking my port speed down to 9600 just for giggles. VOILA!  It works with no problems. HA.
I'm writing this a) to inform others who might go down this path, and b) to pose the question: "is this a possible Hardware issue, or a Arduino/Library Software issue?"
Title: Re: Serial.read baud-rate issues...
Post by: lennevia on September 06, 2018, 10:25:02 AM
To answer your question, it's possible both hardware and software can cause garbage printing issues. The common software issue, as you saw, is the mismatch of baud rates between two communicating devices. The different rates of communication essentially become foreign languages as the data is receiving and transmitting independently and there is chaos, which gives us garbage.
A common hardware issue can occur when trying to communicate with more than two serial devices on one serial bus. When two devices communicate back and forth on one line, there is some order. When there are multiple devices communicating on one line, there is chaos, all devices could be speaking at once or none at all, again producing visual garbage on the Serial Monitor.
Title: Re: Serial.read baud-rate issues...
Post by: Bullwinkle on September 17, 2018, 07:01:25 PM
Well, perhaps I wasn't clear when I said "knocking my port speed down to 9600...": I should have said "I changed both the port speed AND the baud-rate specified in the code" from 115200 to 9600.  There was No mismatch at any time.
As for conflicts, there are none.  Also, I'm not using a hub or intermediate USB connection; I suspect a hardware issue of some sort, but don't have time to worry about it at this point.  Still, would be nice to understand what's going on.
Title: Re: Serial.read baud-rate issues...
Post by: Ben Rose on November 28, 2018, 11:00:19 AM
Just saw this one- For future reference, this is effectively a hardware limitation for the processor. The 8MHz ATmega(any that I've used) have a significant error in the baud rate generation when trying to do 115200. Why does it work one way? The FTDI chipset is 'smarter' and allows for receiving the significant error, but does not apply it back to what it sends to the TinyDuino.

There's another thread referencing the Arduino WiFi firmware updater tool not working. Same issue. I was able to modify the tool to run at 250K baud- much faster, but a rate that the 8MHz processor can generate exactly, so it works fine.

Unfortunately a lot of our older example code used 115200 since it was output only and worked fine. I'm switching things to 9600 as they need updates(when I remember!).
Title: Re: Serial.read baud-rate issues...
Post by: Bullwinkle on December 28, 2018, 03:45:04 PM
Ben,
  Thanks for the confirmation!  (I hadn't been back to this in quite a while, either! :)
I appreciate the follow-up!
Jim
Happy New Year!!!