Atmega USART Problems

Discussion in 'Embedded Systems and Microcontrollers' started by crazyengineer, Dec 8, 2012.

  1. crazyengineer

    Thread Starter Member

    Dec 29, 2010
    156
    2
    Okay, so I thought I had this working, earlier, but lately I've been having difficulty setting this up again. So I'm trying to do simple USART communication but it seems like nothing is writing to the terminal. Here's the code

    Code ( (Unknown Language)):
    1.  
    2. #include <avr/io.h>
    3. #include <util/delay.h>
    4. #define FOSC 8000000 // Clock Speed
    5. #define BAUD 9600
    6. #define MYUBRR FOSC/16/BAUD-1
    7.  
    8.  
    9.  
    10. void USART_Init( unsigned int ubrr)
    11. {
    12. /*Set baud rate */
    13. UBRR0H = (unsigned char)(ubrr>>8);
    14. UBRR0L = (unsigned char)ubrr;
    15. UCSR0B = (1<<RXEN0)|(1<<TXEN0);
    16. /* Set frame format: 8data, 2stop bit */
    17. UCSR0C = (1<<USBS0)|(3<<UCSZ00)| (;
    18. }
    19.  
    20.  
    21. int main( void )
    22. {
    23.  
    24.     USART_Init(MYUBRR);
    25.     while(1)
    26.     {
    27.  
    28.         while ( !( UCSR0A & (1<<UDRE0)) )
    29. ;
    30. /* Put data into buffer, sends the data */
    31.         UDR0 ='d';
    32.  
    33.  
    34.     }
    35.     return 0;
    36. }
    37.  
    I'm using the internal clock of the atmega328p. Also, I'm using a USB to serial converter.

    [​IMG]
     
Loading...