336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

http://extremeelectronics.co.in/avr-tutorials/using-the-usart-of-avr-microcontrollers/

▲레지스터 정리

http://extremeelectronics.co.in/avr-tutorials/using-the-usart-of-avr-microcontrollers-reading-and-writing-data/

▲Reading and Writing Data


(▼AVR Studio 기반)

ATmega8 (USART Test).txt


ATmega128(USART Test).txt


.

.

.

USART of AVR Microcontrollers.

The USART of the AVR is connected to the CPU by the following six registers.

*UDR – USART Data Register

 : Actually this is not one but two register but when you read it you will get the data stored in receive buffer and when you write data to it goes into the transmitters buffer. This important to remember it.

:실질적으로 이건 not one이다. but 두개 레지스터이다.
but when 네가 읽었을때 이걸, 넌 will 얻을것이다. the data를 저장된 in receive버퍼내에,
ane when 네가 썼을때 data를 to it에, 진입해라. the transmitters버퍼로.
이건 중요하니 기억해라.
ATmega128에서는 UDR0로 바꿔준다.

*UCSRA – USART Control and status Register A

 : As the name suggests it is used to configure the USART and it also stores some status about the USART.  There are two more of this kind the UCSRB and UCSRC.

:이름이 제안하듯이, 이건 사용된다. to 구성하기위해 the USART를

and it 또한 저장한다. some 상태를 about the USART에 대한.
두개 더 있다. of 이런 종류가 UCSRB와 UCSRC.
ATmega128에서는 UCSR0BUCSR0C로 바꿔준다.


*UBRRH and UBRRL

 : This is the USART Baud rate register, it is 16BIT wide so UBRRH is the High Byte and UBRRL is Low byte. But as we are using C language it is directly available as UBRR and compiler manages the 16BIT access.

이건 USART Baud Rate 레지스터이다.
이건 16비트 wide이다. so UBRRH는 하이 바이트, UBRRL은 로 바이트이다.
But as 우리가 사용하면서 C언어를, 이건 바로 사용가능하다. as UBRR로.
and 컴파일러는 다룬다. the 16비트 접근을.

ATmega128에서는 UBRR0HUBRR0L로 바꿔준다.


So the connection of AVR and its internal USART can be visualized as follows.


▲USART에서 사용되는 레지스터들

UDR, UCSRA, UCSRB, UCSRC, UBRRH, UBRRL.

★BaudRate설정관련 비트는 (링크) 참고,......UBRRH와 UBRRL을 사용한다.



Registers Explained

In order to write programs that uses the USART 

you need to understand what each register’s importance.

레지스터의 뭐가 중요한지 이해해야한다.

The scheme behind using the AVR USART 

is same as with any other internal peripheral (say ADC).

So if you are new to this topic please see this tutorial

it shows you the basic idea of using peripherals.

I am not going to repeat what is already there in the datasheets, 

I will just tell about what is required for a quick startup. 

The datasheets of AVR 

provides you 

with all the details of every bit of every register 

so please refer to it for detailed info. 

Note bit names with RED background are of our interest here.


UDR : Explained above.

2개의 레지스터로 구성되어있다.

읽으면 data가 저장된다. in Receive Buffer에.

쓰면 data가 빠져나간다. into the Transmit Buffer에.

UCSRA : USART Control and Status Register A

▼아래 비트들은 임무가 완료되면 각각 Set(=1) 된다.

그리고 program이 UDR을 새로 작성한다.

RXC : this bit is set when the USART has completed receiving a byte 

from the host 

(may be your PC) and the program should read it from UDR

TXC : this bit set (1) when the USART has completed transmitting a byte 

to the host 

and your program can write new data to USART via UDR


▼데이터시트에서 뽑아온 UCSRnA 정보이다.

RXCn::This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty.

TXCn::The TXCn flag bit is automatically cleared when a transmit complete interrupt is executed.

UDREn::(USART Data Register Empty)::If UDREn is one, the buffer is empty

FEn::(Frame Error)::Always set this bit to zero when writing to UCSRnA.

DORn::(Data OverRun)::

A data overrun occurs when the receive buffer is full (two characters)

Always set this bit to zero when writing to UCSRnA.

UPEn: Parity Error







UCSRB: USART Control and Status Register B

RXCIE: Receive Complete Interrupt Enable – When this bit is written one the  associated interrupt is enabled.

이 비트가 씌였을때 1로, the 할당된 인터럽트가 Enable 된다. (특수한 경우에 쓰임)

TXCIE: Transmit Complete Interrupt Enable – When this bit is written one the associated interrupt is enabled.

이 비트가 씌였을때 1로, the 할당된 인터럽트가 Enable 된다. (특수한 경우에 쓰임)

RXEN: Receiver Enable - When you write this bit to 1 the USART receiver is enabled.

이 비트가 씌였을때 1로, USART 리시버가 enabled된다.

The normal port functionality of RX pin will be overridden. 

So you see that the associated I/O pin now switch to its secondary function,i.e. RX for USART.

이 비트를 쓰면 to 1로, the USART리시버는 enabled된다.

TXEN: Transmitter Enable – As the name says!

UCSZ2: USART Character Size – Discussed later.

For our first example we won’t be using interrupts so we set UCSRB as follows

UCSRB=(1<<RXEN)|(1<<TXEN);






UCSRC: USART Control And Status Register C

IMPORTANT : The UCSRC and the UBRRH (discussed below) register 

shares same address 

so to determine which register user want to write 

is decided with the 7th(last) bit of data 

if its 1 then the data is written to UCSRC else it goes to UBRRH.

This seventh bit is called the


URSEL: USART Register Select.

UMSEL: USART Mode Select 

– This bit selects between asynchronous and synchronous mode. 

As asynchronous mode is more popular with USART 

we will be using that.

USBS: USART Stop Bit Select 

– This bit selects the number of stop bits in the data transfer.

UCSZ: USART Character size 

– These three bits (one in the UCSRB) 

selects the number of bits of data 

that is transmited in each frame. 

Normally the unit of data in MCU 

is 8BIT (C type "char") 

and this is most widely used 

so we will go for this. 

Otherwise you can select 5,6,7,8 or 9 bit frames!

So we set UCSRC as follows

UCSRC=(1<<URSEL)|(3<<UCSZ0);

UBRR: USART Baud Rate Register:

This is the USART Baud rate register, it is 16BIT wide 

so UBRRH is the High Byte and UBRRL is Low byte. 

But as we are using C language 

it is directly available as UBRR and compiler manages the 16BIT access. 

This register is used by the USART to generate the data transmission at specified speed (say 9600Bps). 

To know about baud rate see the previous tutorial. UBRR value is calculated according to following formula.

Where fosc is your CPU frequency say 16MHz

Baud Rate is the required communication speed say 19200 bps (see previous tutorial for more info).

Example:

For above configuration our UBRR value comes to be 51.083 so we have to set

UBRR=51;

in our initialization section. Note UBRR can hold only integer value. So it is better to use the baud rates that give UBRR value that are purely integer or very close to it. So if your UBRR value comes to be 7.68 and you decided to use UBRR=8 then it has high error percentage, and communication is unreliable!

You may also use our Androd App for calculating the UBRR much easily ! It can run on Smartphones and Tablets running Android OS.

Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백