Atmega8 - USART issue

  • Thread starter Gliese123
  • Start date
In summary: If not, that would also be helpful in understanding how to get started.1-2 months.In summary, the author is trying to establish a radio link between two Atmega8 CPUs. To be able to do this, he follows the datasheet and writes code to initialize the transmitter and receiver. However, he is having difficulty understanding how the radios work and is seeking help from other members of the forum.
  • #1
Gliese123
144
0

Homework Statement


Hi dear PhysicsForum members!
Help in this matter would mean its weight in gold..


I am trying to establish a radio link between two Atmega8 CPUs. However to be able to let these CPUs talk with each other, I have to more or less use the USART or UART as it is also called.
As far as I know, to be able to establish a radio radio link, USART is very good for such a task were the process of receiving an external serial wave has to be implemented into the CPU's register regardless of where the reading of the code may be at the moment.
SO, to do that, I have followed the datasheet as good as I can ( http://www.datasheetarchive.com/dl/Datasheets-UD3/DSAUD0046605.pdf [Broken]) and I'm aware of that I have to initialize the transmitter and the receiver by writing the following code which I eases up the issue a bit:

USART_Init:
; Set baud rate
out
UBRRH, r17​
out
UBRRL, r16​
; Enable Receiver and Transmitter
ldi
r16, (1<<RXEN)|(1<<TXEN)​
out
UCSRB,r16​
;Set frame format: 8data, 2stop bit
ldi
r16, (1<<URSEL)|(1<<USBS)|(3<<UCSZ0)​
out
UCSRC,r16​
ret

(I colored it so it's easier to see for you guys) :)
Obviously the upper coding works. I also wrote this which supposedly is to read and transmit data via USART:

Getchar_UART_Poll:
sbis
USR, RXC​
;
in
r16,UDR​
;UDR turns out to be the register the bits are stored in before Transmit/Receive


PutChar_UART_POLL: ;
sbis
USR, UDRE​
out
UDR, R16​




Homework Equations


We calculated the Baud rate to be 155. Nothing essential, just to let you know that I haven't forgot it.


The Attempt at a Solution


Well, I don't know how I should proceed.. I have sought on the net for countless hours..days.. And I of course read a lot of datasheets. But it doesn't seem to work very well..
Could you please describe to me and maybe give some code examples of how I should proceed next with reading data from it and such. Please describe the obvious things as well.

Note that I am especially bad at understanding how it's working fully. I just know briefly about it as a whole.

Also be aware of that I have to write it in Assembler code with no C syntax, however if you have a very good C code laying around, it would of course be just as good.

~Thanks
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
A couple questions:
1) Is this a one-way or 2-way radio link? Suggest getting a one-way configuration to work before doing a 2-way.
2) What radio resources do you plan on using (modulator, transmitter, antennas, receiver, demodulator)?
3) Can you get the link to work without the radio (using a standard wired connection)? There should be plenty of reference code around to help you get a standard serial link up and running.
 
  • #3
lewando said:
A couple questions:
1) Is this a one-way or 2-way radio link? Suggest getting a one-way configuration to work before doing a 2-way.
2) What radio resources do you plan on using (modulator, transmitter, antennas, receiver, demodulator)?
3) Can you get the link to work without the radio (using a standard wired connection)? There should be plenty of reference code around to help you get a standard serial link up and running.

Thank you lewando for answering!
1 & 2)It's a two way radio link. The radio itself is very simple. What you put into the the first unit is what you get out from the second basically and they are transceivers so they work either direction and vice versa. But yeah, I thought so too.

3) Maybe such try would be the best. Especially since the radio works by the standards as I just described. However, the radios aren't the hard part. Rather the contrary. But what actually happens to the receiving/transmitting register (r16) and how the code should be to be able to utilize the USART.
Unfortunately I haven't been able to make especially much use of the USART yet.
 
  • #4
More:
4) How new at this are you? Have you gotten anything up and running yet, like blinking an LED?
5) I assume you have some kind of development board and a way to program it. Have you tried looking for any examples related to UART comms in whatever environment you have?
6) Here is something specific (maybe helpful): http://www.atmel.com/Images/doc4346.pdf
7) I assume you have at least 2 processor boards--you may need a couple more should one get accidentally smoked. Are these arduinos?
8) What is your timeline for this project?
 
Last edited:
  • Like
Likes 1 person
  • #5
lewando said:
More:
4) How new at this are you? Have you gotten anything up and running yet, like blinking an LED?
5) I assume you have some kind of development board and a way to program it. Have you tried looking for any examples related to UART comms in whatever environment you have?
6) Here is something specific (maybe helpful): http://www.atmel.com/Images/doc4346.pdf
7) I assume you have at least 2 processor boards--you may need a couple more should one get accidentally smoked. Are these arduinos?
8) What is your timeline for this project?

4) Relatively new, however I have been able to blink LEDs in different patterns etc.
5) Yeap. AVR studios. Works really good.
6)THX! :) I haven't seen one of those before. :)
7) Yeah. Sort of.
8) I have done most of hardware etc. Just coding left. I may have 3-4 weeks left and got stuck on USART.

:)
 
  • #6
To further simplify your system, try doing a serial port loopback (connect a wire from the TX pin to the RX pin of the same device). Your job will then be to set up the serial port (baud, mode, etc), enable it, write a character into the TX data register and watch it appear in the RX data register. By the way, how will you know if this is happening correctly or not? Are you using the debugger to get register/memory visibility?

AVR Studio should have some reference projects related to the UART, yes?
 
  • Like
Likes 1 person
  • #7
lewando said:
To further simplify your system, try doing a serial port loopback (connect a wire from the TX pin to the RX pin of the same device). Your job will then be to set up the serial port (baud, mode, etc), enable it, write a character into the TX data register and watch it appear in the RX data register. By the way, how will you know if this is happening correctly or not? Are you using the debugger to get register/memory visibility?

AVR Studio should have some reference projects related to the UART, yes?
Ah yes! I tested it on Friday afternoon and it worked from the one port of the CPU to the other! But connecting TX-->RX is very smart! I'll try doing that as well to be even more acquainted with the system properties :D

I am using a logic analyzer to see if the bits I send are correct. I should be able to do it in the code as well by checking bits.
 

What is the purpose of the USART in Atmega8?

The USART (Universal Synchronous/Asynchronous Receiver/Transmitter) in Atmega8 is a serial communication interface that allows the microcontroller to communicate with external devices, such as sensors, displays, and other microcontrollers.

Why am I not able to receive data through USART on my Atmega8?

There could be several reasons why you are not able to receive data through USART on your Atmega8. Some common causes include incorrect configuration of the USART registers, faulty hardware connections, and incorrect baud rate settings. It is important to double check all of these factors to ensure proper communication.

How do I configure the baud rate for USART communication on Atmega8?

The baud rate for USART communication on Atmega8 can be configured by setting the value of the UBRR (USART Baud Rate Register) based on the desired baud rate and the system clock frequency. The formula for calculating the UBRR value is provided in the Atmega8 datasheet.

What is the difference between synchronous and asynchronous communication in USART?

In synchronous communication, the transmitter and receiver are synchronized by a common clock signal, while in asynchronous communication, the transmitter and receiver use their own separate clocks. This means that in synchronous communication, data is transmitted in a continuous stream, while in asynchronous communication, data is transmitted in separate chunks with start and stop bits.

Can I use the USART for both transmitting and receiving data simultaneously on Atmega8?

Yes, the USART on Atmega8 supports full-duplex communication, meaning it can simultaneously transmit and receive data. This is possible by using separate transmit and receive pins and configuring the USART registers appropriately.

Similar threads

  • Electrical Engineering
Replies
4
Views
1K
Back
Top