Serial communication giving unexpected results.

Go To Last Post
17 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I'm programming an Atmega328P with Atmel Studio 7 and an Atmel ICE.  I've followed a few samples regarding serial communication with FDTI module, and have used a few different Windows programs to monitor serial traffic (XCTU, Tera Term, etc).  In each, I can see communication coming from the device, but the data is not what is expected.  The device is sending the character 'C', however, the computer does not receive the correct character.  Based on the tutorials I've been following, I haven't been able to identify the issue.  Can you please point me in the right direction if I have any programming issues or if there are any environment settings that may come in to play?  I've attached a circuit diagram, the source code I'm using, and the results of the serial communication.

 

Thanks!

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#ifndef F_CPU					// if F_CPU was not defined in Project -> Properties
#define F_CPU	1000000UL		// define it now as 1 MHz unsigned long
#endif

Is F_CPU defined elsewhere as other then 1 MHZ? What is your board's clock? The define doesn't change it but the fuses do as well as any external crystal.

 

And I hope that your circuit is a bit more filled in than what you show.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum.

 

There are many App's that show the serial communication's baud rate error for any given clock frequency.

 

An old one is AVRCalc.

 

It shows that a 9600 baud rate with a micro clock of 1 MHz has a 7.8 % baud rate error.

 

That will never work.

 

You need the error to be < 2%, and preferable a lot less.

 

Do you have an crystals you can use, (and CAREFULLY reset the Fuses so that the micro uses it)?

 

You could also try setting the uC to run on its internal RC Osc at 8 MHz, which would give an error of 0.16 %, IF the internal Osc is actually running at 8.00 MHz.

It will likely be off a little, and there are ways to correct for that, but that is another story for another time.

 

Secondly, although it is not likely the problem at the moment, your schematic doesn't show any "By-Pass" capacitors.

You need a 0.1 uF cap across the Vcc/Ground and the AVcc/Ground pairs of pins, as close to the pins on the micro as you can put them, for reliable operation.

 

If you order some external crystals from Mouser, or elsewhere, there are baud rate friendly frequencies.

For 9600  an Xtal of 14.746 MHz gives a 0% baud rate error.

 

The Xtal would need two capacitors, one from each leg to Ground.

There are appropriate ways, based upon the specific crystal, to calculate these, but typically something from 12 to 20 pF should work fine.

 

JC

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...and no common ground between chip and FTDI module...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I turned off the CKDIV8 fuse and updated the code to account for 8MHz clock speed and it is working now!!!  I'll check out your suggestions around the capacitors and external crystals.  Thank you for your help!

 

Glen

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Another one that forgot to use a crystal?  Not sure when this disease started, or if there is a cure.  Maybe one year there was a severe crystal shortage & everyone was ordered to stop using thm.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think some just want to avoid the mystical properties of crystals...

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Crystals are simply an annoyance and take up board space, like bypass caps and TWI pull-up resistors.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and batteries?

 

Batteries are really annoying!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

laugh

the unconditionally stable and ultra-low noise power supply ... other than the low frequency noise due to discharge

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can easily create basic USART application for Atmega328P on start.atmel.com. Just add basic USART component and configure it. If you select Async IRQ mode don't forget to enable Global Interrupt in CPU settings. You will find generated usart_basic_example.c code in "View code" /examples/src
 

You can export the project and import it in the MPLAB X IDE or Atmel Studio.

Last Edited: Wed. Feb 12, 2020 - 05:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Crystals are simply an annoyance and take up board space, like bypass caps and TWI pull-up resistors.

Someone needs to sell a little DPAK size micro-module that contains a crystal, few uf AVR supply bypass caps, pull up resistors and a couple of status leds (with resistors).

So all you need is your AVR & one of these & you'll be freaking.  Sort of the kitchen sink for hookups.

 

You saw it here first.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
Someone needs to sell a little DPAK size micro-module that contains a crystal, few uf AVR supply bypass caps, pull up resistors and a couple of status leds (with resistors).

How about a kit of obsolete through hole parts for the script kiddies.  Could be a way to fund this site if MC put that together! devil

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

avrcandies wrote:
You saw it here first.

No, I think we've seen it already; eg,

 

EDIT

 

Better image

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Feb 12, 2020 - 08:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kevil wrote:
You can easily create basic USART application for Atmega328P on start.atmel.com.
You can if you are stark staring bonkers. Most folks would not go anywhere near the bloat factory for something as trivial as some UART routines !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Surely with a mega328 you'd start with Arduino? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Surely with a mega328 you'd start with Arduino? 

Or Peter Fleury:  http://www.peterfleury.epizy.com...

He has lib's for USART, TWI (I2C) and LCD, OP should grab all three, they will be useful for just about any project.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...