Serial headaches - Page 1
Forum section: electronics / general

author: rexxar
author_rank: Frequent Contributor
timestamp: April 21, 2015, 01:51:23 am
content: I'm really tearing my hair out over this one. My microcontroller absolutely refuses to communicate with the PC side software, and I cannot for the life of me figure out what is going on. The software sends out plain ASCII serial commands. In this case, it's sending the word 'params'. When I use my software to do it, the micro doesn't acknowledge ANY serial input. At all. If, however, I type 'params' into PuTTY, it responds and gives me the data I asked for.My logic analyzer showed that the commands are identical coming from both PuTTY and my software. I eventually hooked up my scope because I can't think of anything else. I attached some screenshots. White waveform is from PuTTY and the mirco will respond to it and print out its response. Yellow trace is the exact same command from my software. Almost exactly the same, except those two edges are lagging behind the other trace.Surely those two edges can't be the cause of my problems, could it? This is baffling because I have debug code in right now that will print a message to the serial terminal if it receives a byte, and there's two or three good bytes before that first bad edge.I'm completely at a loss here, and any hints would be greatly appreciated!Relevant details: ATmega328 microcontroller, with a Cypress CY7C65213 USB to serial converter. Software is a Perl thing my partner wrote.

author: hamster_nz
author_rank: Super Contributor
timestamp: April 21, 2015, 02:00:01 am
content: Are you turning off hardware flow control in your software?

author: rexxar
author_rank: Frequent Contributor
timestamp: April 21, 2015, 02:10:11 am
content: Quote from: hamster_nz on April 21, 2015, 02:00:01 amYes.

author: hamster_nz
author_rank: Super Contributor
timestamp: April 21, 2015, 03:31:44 am
content: Quote from: rexxar on April 21, 2015, 02:10:11 amWhen you say " When I use my software to do it", this is your software on the PC?Have you tried just linking the TX and RX pins on the serial pins, and taking your micro out of the loop completely?Under Putty it should just echo what you type, on your software it should do the same too... if you write "XYZ" you should get "XYZ" back.

author: rexxar
author_rank: Frequent Contributor
timestamp: April 21, 2015, 03:51:04 am
content: Quote from: hamster_nz on April 21, 2015, 03:31:44 amYes.QuoteI've tried that as well, it works as expected. I've got two boards, and they both show the same behavior, so I'm 99% sure it's not a hardware issue. Serial works just fine with PuTTY and the Arduino IDE.

author: hamster_nz
author_rank: Super Contributor
timestamp: April 21, 2015, 04:01:27 am
content: When in Putty, your characters are going as fast as you can type (I am guessing).What happens if you type slowly (a couple of chars per sec), and can you put a similar pause between sending characters in your software?Maybe the start bit of the following character is messing up the stop bits, causing the character to be thrown away....

author: rexxar
author_rank: Frequent Contributor
timestamp: April 21, 2015, 04:30:16 am
content: Quote from: hamster_nz on April 21, 2015, 04:01:27 amI've got code running on the micro that will print a message every time a byte arrives in the serial buffer. I don't get any of the debug messages.......It suddenly started working all on its own. All I did was flash a test firmware, then go back to the real code and it's working. What?!I'm going back to one of my earlier theories: This board has become sentient and it hates me.

author: electr_peter
author_rank: Unknown
timestamp: April 21, 2015, 07:01:37 am
content: Serial communication is not that simple when take into account PC SW, drivers, USB HW/SW, USB->TTL conversion, timing, ...In short, serial has many hidden traps one can fall into. I suspect PC SW not working properly in this case.

author: tom66
author_rank: Super Contributor
timestamp: April 21, 2015, 07:50:53 am
content: If you baud rate was marginal (e.x. you set it to 10000bps and transmit 9600bps) you could get this issue. Can the MCU talk to itself? Try a loop back from TX to RX...

author: sacherjj
author_rank: Frequent Contributor
timestamp: April 22, 2015, 05:13:22 pm
content: I ran into something like this and wound up using Python with the serial module to vary baud by 100 at a time and try to send and receive over the serial. I tried it 10 times and logged errors. I found that the crystal was shifted enough that 9600 was right on the edge and it connected solid at 10100 baud.I swapped out the crystal to a proper UART multiple crystal and solved the occasional issues.