Solved: Problems with USART (Only sends €)

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

Good afternoon everybody.

 

I've recently tried to program an ATmega16 to do serial communication with my computer using a very simple code of serial communication (just send and receive data). Sadly, when I check how the circuit works it only sends one data, €, which in ASCII is an 1's byte, which crearly shouldn't happen since it isn't a data I am programming to send in any situation. I don't know if it has something to do with the UDR register or if the programmer (USBASP) or the USB to TTL Bridge malfunctions. Any help would be of great appreciation.  My .c file from my AVR Studio project is attached below. 

Attachment(s): 

Last Edited: Wed. May 16, 2018 - 04:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Not sure if the mega16 has a div8 fuse but it sounds like your clock is not correct for your baud rate. Not in front of the datasheet so maybe another freak could confirm the div8 fuse existence

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

Thank you. I didn't find the DIV8 fuse but checked the default clock of the uC and was at 1MHz and after changing it it begun to work correctly.

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

Atmega16 has four internal oscillators

1, 2, 4, 8 MHz

 

If you did not change fuses, the chip runs at 1 MHz and you have to write F_CPU = 1000000.

 

Edit:

For test use a printable character, for example

while(1)
{
    send('A');
    _delay_ms(1000);
}    
      

 

Last Edited: Wed. May 16, 2018 - 03:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Visovian wrote:
For test use a printable character, for example while(1) { send('A');

Send 'U'.  Then, at 8-n-1 you get a square wave output, 50% duty cycle, that can be observed (and bit width measured) with a 'scope, or read with a frequency meter.

 

Visovian wrote:
you have to write F_CPU = 1000000.

Hmmm-- I guess we can infer from the attachment that it is GCC.  And then the #define cannot have the =

 

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:
And then the #define cannot have the =
He may have been talking about AS7. In the project section where you make defines you would enter F_CPU=12345 or whatever and this would then be passed as a -DF_CPU=12345 which has the same effect as a #define without the =.

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

IF OP does not use Xal, but internal oscillator, -s-he will get some issues (frequency drifts leading to baud rate unstable)  if temperature/MCU/luck changes....

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

It seems we did not help him at all.

He marked the thread "solved" and did not care to tell us more.

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

Please read post # 3 again.... carefully.

 

Ross McKenzie ValuSoft Melbourne Australia

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

(Only sends €)

I was hoping to replicate the "problem" and change it so that it would send me AU$ but Euros are OK. cheeky

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Visovian wrote:
He marked the thread "solved"

Well, he edited the title.

 

For the proper way to mark the solution, see Tip #5 ...

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

Sorry, I have overlooked #3.