Author Topic: Serial headaches  (Read 4457 times)

0 Members and 1 Guest are viewing this topic.

Offline rexxarTopic starter

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: us
    • Forever Tinkering
Serial headaches
« on: April 21, 2015, 01:51:23 am »
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.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2812
  • Country: nz
Re: Serial headaches
« Reply #1 on: April 21, 2015, 02:00:01 am »
Are you turning off hardware flow control in your software?

Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline rexxarTopic starter

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: us
    • Forever Tinkering
Re: Serial headaches
« Reply #2 on: April 21, 2015, 02:10:11 am »
Are you turning off hardware flow control in your software?
Yes.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2812
  • Country: nz
Re: Serial headaches
« Reply #3 on: April 21, 2015, 03:31:44 am »
Are you turning off hardware flow control in your software?
Yes.

When 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.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline rexxarTopic starter

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: us
    • Forever Tinkering
Re: Serial headaches
« Reply #4 on: April 21, 2015, 03:51:04 am »
When you say " When I use my software to do it", this is your software on the PC?
Yes.
Quote
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.

I'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.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2812
  • Country: nz
Re: Serial headaches
« Reply #5 on: April 21, 2015, 04:01:27 am »
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....
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline rexxarTopic starter

  • Frequent Contributor
  • **
  • Posts: 439
  • Country: us
    • Forever Tinkering
Re: Serial headaches
« Reply #6 on: April 21, 2015, 04:30:16 am »
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....

I'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.
 

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1431
  • Country: lt
Re: Serial headaches
« Reply #7 on: April 21, 2015, 07:01:37 am »
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.
 

Offline tom66

  • Super Contributor
  • ***
  • Posts: 7217
  • Country: gb
  • Electronics Hobbyist & FPGA/Embedded Systems EE
Re: Serial headaches
« Reply #8 on: April 21, 2015, 07:50:53 am »
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...
 

Offline sacherjj

  • Frequent Contributor
  • **
  • Posts: 993
  • Country: us
Re: Serial headaches
« Reply #9 on: April 22, 2015, 05:13:22 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf