while(!( UCSRA & (1<<UDRE))) {
/* USART data register is not Empty, keep looping */
}
UDR = somechar; /* store the character into the data register */
/* USART transmit is automatically started by writing to UDR */
In more complicated situations you’d set up an interrupt routine which would be invoked by the USART when it’s ready to accept another byte, and the ISR would retrieve the byte from a fifo or ring buffer somewhere.
/* USART data register is not Empty, keep looping /
}
UDR = somechar; / store the character into the data register /
/ USART transmit is automatically started by writing to UDR */
In more complicated situations you'd set up an interrupt routine which would be invoked by the USART when it's ready to accept another byte, and the ISR would retrieve the byte from a fifo or ring buffer somewhere.
winl,
Thanks for responding. I have used exactly the same thing which I got from datasheet. But still have problem. The problem seems to be in initializing the UART. If you can not initialize then not transmission or reception. Can you please have a look at the initialization part? I tried like the above and like the datasheet, with WinAVR and with Codevision. I could not do it.
Here is what I have or do:
A laptop with only one serial com1, I connect this com1 to RS232 CTRL of STK500 After downloading the program to AVR, I take the serial cable connected to PC and connect it to RS232 spare of STK500, establish connection between the STK500 and Brays++ terminal but nothing happens.
The setting on Bray++ and STK500 are the same, or so I believe not sure about STK500.
I didn’t look closely at your UART setup code, but just wanted to assure you know that printf() and puts() and the rest of the stdio cannot work unless you connect a low level UART output function with the C library stdio functions. With GCC/WinAVR, it’s done as mentioned above, and as documented in WinAVR’s help files.
The most common newbie error in UARTs is calculating the baud rate incorrectly, e.g., crystal frequency, etc. There are two or three nice freeware utilities to calculate the settings: AVRcalc is one I can recall.
also, check out the examples in the projects section of avrfreaks.net such as
stevech:
I didn’t look closely at your UART setup code, but just wanted to assure you know that printf() and puts() and the rest of the stdio cannot work unless you connect a low level UART output function with the C library stdio functions. With GCC/WinAVR, it’s done as mentioned above, and as documented in WinAVR’s help files.
The most common newbie error in UARTs is calculating the baud rate incorrectly, e.g., crystal frequency, etc. There are two or three nice freeware utilities to calculate the settings: AVRcalc is one I can recall.
also, check out the examples in the projects section of avrfreaks.net such as
You’ll then be using the RC oscillator inside the microcontroller. If you open up the STK500 programming window, there is a section where you set the oscillator speec.
I usually don’t find RC oscillators steady and consistent enough for UART communication, especially at higher speeds.
theatrus:
You’ll then be using the RC oscillator inside the microcontroller. If you open up the STK500 programming window, there is a section where you set the oscillator speec.
I usually don’t find RC oscillators steady and consistent enough for UART communication, especially at higher speeds.