http://www.8051projects.net/mediawiki/index.php?title=AVR_UART/Serial_Communication_Tutorial&feed=atom&action=history
AVR UART/Serial Communication Tutorial - Revision history
2024-03-29T13:22:55Z
Revision history for this page on the wiki
MediaWiki 1.28.0
http://www.8051projects.net/mediawiki/index.php?title=AVR_UART/Serial_Communication_Tutorial&diff=171&oldid=prev
Ajay Bhargav: /* Help & Queries */
2015-03-06T13:27:24Z
<p><span dir="auto"><span class="autocomment">Help & Queries</span></span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;' lang='en'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 13:27, 6 March 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l86" >Line 86:</td>
<td colspan="2" class="diff-lineno">Line 86:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Help & Queries ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Help & Queries ==</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>If you have any queries, doubts or feedback on this tutorial please share in our [http://www.8051projects.net/forum.html discussion forum].</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>If you have any queries, doubts or feedback on this tutorial please share in our [http://www.8051projects.net/forum.html discussion forum].</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">[[Category:Tutorials]]</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Serial Port Peripherals]]</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Serial Port Peripherals]]</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">[[Category:AVR Tutorials]]</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>{{#seo:</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>{{#seo:</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>|title=<del class="diffchange diffchange-inline">8051 </del>Uart/Serial Communication Tutorial</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>|title=<ins class="diffchange diffchange-inline">AVR </ins>Uart/Serial Communication Tutorial</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>|keywords=Serial Communication, UART, USART, MAX232 intefacing, MAX232 with microcontroller, <del class="diffchange diffchange-inline">8051 communication</del>, AVR serial communication</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>|keywords=Serial Communication, UART, USART, MAX232 intefacing, MAX232 with microcontroller, <ins class="diffchange diffchange-inline">AVR UART Tutorial</ins>, AVR serial communication</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|description=Serial communication using UART or USART of a microcontroller 8051 AVR PIC, software implementation of half-duplex UART and MAX232 interfacing with microcontrollers 8051 AVR PIC.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|description=Serial communication using UART or USART of a microcontroller 8051 AVR PIC, software implementation of half-duplex UART and MAX232 interfacing with microcontrollers 8051 AVR PIC.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}}</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}}</div></td></tr>
</table>
Ajay Bhargav
http://www.8051projects.net/mediawiki/index.php?title=AVR_UART/Serial_Communication_Tutorial&diff=133&oldid=prev
Ajay Bhargav: Initial commit AVR serial
2015-02-25T11:24:41Z
<p>Initial commit AVR serial</p>
<p><b>New page</b></p><div>In AVR, following set of registers are used to communicate over USART<br />
<br />
*UCSRA<br />
*UCSRB<br />
*UCSRC<br />
*UBRRH<br />
*UBRRL<br />
<br />
'''UCSRA:''' in this register there are flags for various errors that might occur during data transmission, e.g. parity error, frame error etc.<br />
<br />
'''UCSRB:''' in this register we have a lot of enable bits. For example different interrupt enable bits but also the receiving and transmitting enable bits.<br />
<br />
'''UCSRC:''' in this register we set the parity mode, stop bits and so on.<br />
<br />
'''UBRRH & UBRRL:''' in UBRRH register, the higher byte and in UBRRL, lower byte is stored for generating a required Baud rate.<br />
<br />
More information on the above registers can be found in the datasheet of the AVR you are using.<br />
<source lang="asm">.include \"m8515def.inc\"<br />
.def reg1 = r16<br />
.def reg2 = r17<br />
Serial_Init:<br />
;Load UBRRH with 0 and UBRRL with 25<br />
;to set a baud rate of 9600 at 4MHz<br />
ldi reg1,00<br />
out UBRRH,reg1<br />
ldi reg2,25<br />
out UBRRL,reg1<br />
;Clear all error flags<br />
ldi reg1,00<br />
out UCSRA,reg1<br />
;Enable Transmission and Reception<br />
ldi reg1,(1<<RXEN)+(1<<TXEN)<br />
out UCSRB,reg1<br />
;Set Frame format<br />
;8,N,1<br />
ldi reg1,(1<<URSEL)|(3<<UCSZ0)<br />
out UCSRC,reg1<br />
ret<br />
</source><br />
Intialization in C is bit straight forward as we say...<br />
<source lang="c">#include <avr/io.h>.<br />
void serial_init(){<br />
UCSRA=0x00;<br />
UCSRB=0x18;<br />
UCSRC=0x86;<br />
UBRRH=0x00;<br />
UBRRL=0x19;<br />
}<br />
</source><br />
To transmit data serial we need to put the data to send in 8-bit UDR (UART Data Register) and poll the empty transmit buffer to set. While receiving data we wait for the receive flag, when its set the data recieved can be read from the UDR register. Here is an example to implement this in assembly:<br />
<source lang="asm">Serial_Send:<br />
;wait for empty transmit buffer flag<br />
sbis UCSRA, UDRE<br />
rjmp Serial_Send<br />
;If the flag is set<br />
;Then move the data to send in UDR<br />
out UDR,reg2<br />
ret<br />
<br />
Serial_Read:<br />
;Wait for Receive flag<br />
sbis UCSRA,RXC<br />
rjmp Serial_Read<br />
;If falg is set<br />
;Then read data from UDR<br />
in reg2,UDR<br />
ret<br />
</source><br />
Similarly in C:<br />
<source lang="c">void serial_send(unsigned char dat){<br />
while(!(UCSRA & (1<<UDRE)));<br />
UDR = dat;<br />
}<br />
unsigned char serial_read(){<br />
while(!(UCSRA & (1<<RXC)));<br />
return UDR;<br />
}<br />
</source><br />
== See Also ==<br />
* [[UART Communication Tutorial]] - Basics of UART<br />
* [[8051 UART/Serial Communication Tutorial]]<br />
* [[8051 Software UART Tutorial]]<br />
* [[GPS Receiver Interfacing over UART Tutorial]]<br />
* [[GSM Modem Interfacing over UART Tutorial]]<br />
<br />
== Help & Queries ==<br />
If you have any queries, doubts or feedback on this tutorial please share in our [http://www.8051projects.net/forum.html discussion forum].<br />
<br />
[[Category:Tutorials]]<br />
[[Category:Serial Port Peripherals]]<br />
<br />
{{#seo:<br />
|title=8051 Uart/Serial Communication Tutorial<br />
|keywords=Serial Communication, UART, USART, MAX232 intefacing, MAX232 with microcontroller, 8051 communication, AVR serial communication<br />
|description=Serial communication using UART or USART of a microcontroller 8051 AVR PIC, software implementation of half-duplex UART and MAX232 interfacing with microcontrollers 8051 AVR PIC.<br />
}}</div>
Ajay Bhargav