'USART'에 해당되는 글 1건

  1. 2009.10.07 ATmega128 USART 사용하기
embeded/AVR (ATmega,ATtiny)2009. 10. 7. 23:13
us-tech 사의 제품을 사용해서, 아래 링크의 예제를 사용하려고 했더니.
outp 매크로를 이용하는 구버전이라서 조금 고민하다가 데이터시트를 읽고 시도했다.

    /* for USART */
    UBRR0H = 0;
    UBRR0L = 8; // 115200bps with U2X = 0
    UCSR0A = 0x00; // U2X = 0;
    UCSR0B = 0xF8;
    UCSR0C = 0x06; // Asyncronous - no parity - 1bits(stop) - 8bits(data)


USART Baud Rate Register (UBRR) 은 일종의 divider의 설정값으로, 클럭을 분기하는데 사용하는 값이라고 생각이 된다.
아무튼 16.0MHz 같은녀석은, Error 율이 0% 인녀석이 일반적으로 사용하는 115k 이하에는 없으므로 그리 좋지 않다.

그리고 U2X는
Bit 1 – U2Xn: Double the USART Transmission Speed
This bit only has effect for the asynchronous operation. Write this bit to zero when using synchronous operation.
Writing this bit to one will reduce the divisor of the baud rate divider from 16 to 8 effectively doubling the transfer rate for asynchronous communication
라고 나와있 듯, asynchronous 모드에서만 작동이 되며, 클럭을 두배로 증가시켜 에러율을 줄이는 효과를 보인다.

아무튼, USART / UART를 설정하는데 사용되는 레지스터는
UCSR0A, UCSR0B, UCSR0C 세가지가 있으며

UCSR0A에는 U2X를 제외하면 실질적으로 전부 Status 레지스터이다.
• Bit 7 – RXCn: USART Receive Complete
• Bit 6 – TXCn: USART Transmit Complete
• Bit 5 – UDREn: USART Data Register Empty
• Bit 4 – FEn: Frame Error
• Bit 3 – DORn: Data OverRun
• Bit 2 – UPEn: Parity Error
• Bit 1 – U2Xn: Double the USART Transmission Speed
• Bit 0 – MPCMn: Multi-Processor Communication Mode

UCSR0B에는 인터럽트와 , TX / RX enable 를 설정하며
• Bit 7 – RXCIEn: RX Complete Interrupt Enable
• Bit 6 – TXCIE: TX Complete Interrupt Enable
• Bit 5 – UDRIEn: USART Data Register Empty Interrupt Enable
• Bit 4 – RXENn: Receiver Enable
• Bit 3 – TXENn: Transmitter Enable
• Bit 2 – UCSZn2: Character Size
• Bit 1 – RXB8n: Receive Data Bit 8
• Bit 0 – TXB8n: Transmit Data Bit 8

UCSR0C에는 눈에 익숙한 N-8-1 (No Parity - 8bit data - 1bit stop) 이러한 설정값을 조절한다.
• Bit 7 – Reserved Bit
• Bit 6 – UMSELn: USART Mode Select
• Bit 5:4 – UPMn1:0: Parity Mode
• Bit 3 – USBSn: Stop Bit Select
• Bit 2:1 – UCSZn1:0: Character Size
• Bit 0 – UCPOLn: Clock Polarity


데이터를 TX로 출력하려면 UDR0 = data; 를 하면된다.




[링크 : http://www.us-technology.co.kr/lecture/lecture_main.asp?mode=1&smode=6]
Posted by 구차니