1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Atmega8 - USART issue

  1. Feb 20, 2014 #1
    1. The problem statement, all variables and given/known data
    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 eachother, 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 ​




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


    3. 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: May 6, 2017
  2. jcsd
  3. Feb 20, 2014 #2

    lewando

    User Avatar
    Gold Member

    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.
     
  4. Feb 20, 2014 #3
    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.
     
  5. Feb 20, 2014 #4

    lewando

    User Avatar
    Gold Member

    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: Feb 20, 2014
  6. Feb 21, 2014 #5
    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.

    :)
     
  7. Feb 21, 2014 #6

    lewando

    User Avatar
    Gold Member

    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?
     
  8. Feb 23, 2014 #7
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Atmega8 - USART issue
  1. Issue with Mathematica (Replies: 2)

  2. MATLAB - interp1 Issue (Replies: 3)

  3. Java Tokenizer Issues (Replies: 1)

  4. Truss Issues (Replies: 6)

Loading...