Atmega1608 won't execute USART

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

Hi there,

 

I'm a beginner with AVR.

My goal is to use UART with a ATMEGA1608. For software I am using the Atmel Start generated project and libraries.

Just to test if something happens I wrote simple program and measure the RX and TX pins with a oscilloscope.

The pins a pulled high but won't send/receive anything (pins are not getting pulled low).

 

Here is my code:

 

#include <stdio.h>
#include <string.h>
#include <atmel_start.h>
#include <usart_basic_example.h>
#include <usart_basic.h>
#include <atomic.h>
#include <util/delay.h>


void send_uart(){
	
	
	USART_1_MAIN_write(10);
	
	
	
	}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	
	
	

	/* Replace with your application code */
	while (1) {
		
		send_uart();
		 _delay_ms(2000);
		
	}
}

 

Hope you can help me

Thank you

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

 RX and TX pins with a oscilloscope.

A very smart move!!  That is great news.

 

You should first forget about the uart & try just toggling a pin (such as the TX pin)...can you see that on the scope?? If not then fiddling with the uart is out of the question, until you do.\

 

Unfortunately the code you show has everything hidden away ...like calling make_toast_now(2) and saying why does nothing happen?

Have you configured the port direction properly?  Are you monitoring the proper pin?  worry ONLY about sending now...don't stop until you see pulses on the scope.

Setting the Uart clock to the proper freq is critical, though any non-zero clocking should at least show something on the scope.

What are you trying to send?  ...start by sending the char capital U, or really any single character that will give some pulses.  

Reduce your delay to 10ms...so you can see a steady non-stop stream of the character spitting out on your scope.

 

Once you verify something coming out of TX, you can tie that to RX and see the chars coming back in...that will be work for later

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

Last Edited: Thu. May 21, 2020 - 09:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
You should first forget about the uart & try just toggling a pin

Agree - begin at the beginning!

 

See: https://www.avrfreaks.net/commen...

 

And more beginner "getting started" tips at #6 in my signature, below:

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: Thu. May 21, 2020 - 09:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
start by sending the char capital U, or really any single character

The uppercase 'U' is the best - as it gives you a good, steady square wave to view on your scope.

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: 1
int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	
	
	

	/* Replace with your application code */

I don't know "Start" that well but I kind of doubt that atmel_start_init() includes any kind of uart_init() specific function so I suspect you are attempting to use the UART without initialising it.

 

I just tried this in Start and it seems to create some kind of uart_basic.c file which contains a USART_init() function.

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

clawson wrote:
I kind of doubt that atmel_start_init() includes any kind of uart_init() specific function

 

well, it says "Initializes MCU, drivers and middleware" - so I would have thought that would include all the peripheral initialisation you had asked START to do for you!

 

But I also haven't used START myself but, from Jim's experience, it doesn't always seem to do the "obvious" thing:

 

https://www.avrfreaks.net/commen...

 

frown

 

Aha - I made the same point as you:

 

https://www.avrfreaks.net/commen...

 

But it looks like Jim gave up with START before trying that.

 

 

 

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

So after some tweaking I got something out of the pin.

 

For some reason Atmel start did not process my config and the async mode was not enabled by default and I had to enable it by changing the usart_basic.c file.

 

But the output is not what I've programmed.

 

I am trying to decode it with a raspberry pi now.

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

SlashB wrote:

 


void send_uart(){
	
	
	USART_1_MAIN_write(10);
	
	
	
	}



 

 

What are you expecting to see? It certainly won't be the numbers '10' if that's what you are looking for.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

I know.

 

I've send a character.

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

SlashB wrote:
I've send a character.
But 10 is character '\n' (new line). Is that really what you were hoping to see? (philosophical question: can one "see" a newline when it's really a form of white space? Discuss!)

 

I'd do something like

USART_1_MAIN_write('A');

Very difficult to miss an 'A' when one (or in this case, many) come along!

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

I did it with "U" as you suggested. My oscilloscope has a decode function

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

I did it with "U" as you suggested. My oscilloscope has a decode function

Did it appear properly...measure the exact timing/freq & if proper, you should be able to rcv it on a PC terminal.

You can also loop it back & now RX it into your AVR.

 

note--if you loop back, any frequency error will become hidden (RX & TX will both be equally misclocked)...so you might say "loopback works great, I'm all done !!!!"  but yet you can't talk to any other device (like a PC or other equipment)

 

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

It does not appear. How can it be a frequency error? I set up everything with Atmel start and used the exact  same parameters in my terminal.

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

How have you set your fuses?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

I did it with "U" as you suggested. My oscilloscope has a decode function

What DID you see?    Are you using a decent crystal to establish the proper UART frequency?....As mentioned check the OSC fuses to ensure they are proper.  Since you have a scope you can measure the timings of the waveforms & check for proper rate.

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

Last Edited: Sun. May 24, 2020 - 04:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've just used the debug function, so no fuses are set

 

Edit:

I have noticed some weird thing. The RXD pin is at roughly 2.3V nothing attached to it

Last Edited: Sun. May 24, 2020 - 07:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The RXD pin is at roughly 2.3V nothing attached to it

Why is that weird??--you just said you have nothing to take it high or low.  It would typically go to Vcc/2 which can be dangerous for some gates ,causing both halves of the front end cross-conducting & possible damages (though rare these days).  At least turn on the pullup!!

 

You have yet to say what your scope is showing--why?

 

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

Ok the pins were set to a idle low and no pullup on RXD. I've changed that in the Atmel start config but my oscilloscope shows nothing just both pins at 3.3V

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

I would go simple, create a single file like below, and either just get the tx pin to toggle or send something-

 

https://godbolt.org/z/rAZC_b

 

Now it may be that just looking at that file will trigger some light bulb- like maybe you are using the wrong usart for the pins in use, or you are using the alternate pins and did not set portmux, etc.

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

I realize you are trying to use START, but why not use the information available in the "Getting Started with USART" app note?

David (aka frog_jr)