Port uart driver to atmega32

This commit is contained in:
Nero 2018-04-04 22:35:09 +00:00 committed by Nero
parent 799870e1f1
commit 00a8c7546f
4 changed files with 64 additions and 8 deletions

View File

@ -4,7 +4,8 @@
#define BAUD_PRESCALE (((F_CPU/(BAUDRATE*8UL)))-1)
void __attribute__ ((naked)) __attribute__ ((section (".init5"))) uart_init() {
UCSR0A = (1<<U2X0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); // 8N1
UBRR0 = BAUD_PRESCALE;
UCSRA = (1<<U2X);
UCSRC = (1<<UCSZ0) | (1<<UCSZ1); // 8N1
UBRRH = (BAUD_PRESCALE>>8);
UBRRL = BAUD_PRESCALE;
}

View File

@ -0,0 +1,55 @@
#ifndef U2X
#define U2X U2X0
#endif
#ifndef UCSZ0
#define UCSZ0 UCSZ00
#endif
#ifndef UCSZ1
#define UCSZ1 UCSZ01
#endif
#ifndef TXEN
#define TXEN TXEN0
#endif
#ifndef RXEN
#define RXEN RXEN0
#endif
#ifndef RXCIE
#define RXCIE RXCIE0
#endif
#ifndef UDRE
#define UDRE UDRE0
#endif
#ifndef UCSRA
#define UCSRA UCSR0A
#endif
#ifndef UCSRB
#define UCSRB UCSR0B
#endif
#ifndef UCSRC
#define UCSRC UCSR0C
#endif
#ifndef UBRRH
#define UBRRH UBRR0H
#endif
#ifndef UBRRL
#define UBRRL UBRR0L
#endif
#ifndef UDR
#define UDR UDR0
#endif
#ifndef USART_RX_vect
#define USART_RX_vect USART_RXC_vect
#endif

View File

@ -4,7 +4,7 @@
#include <avr/interrupt.h>
void __attribute__ ((naked)) __attribute__ ((section (".init6"))) uart_rx_init() {
UCSR0B |= (1<<RXEN0) | (1<<RXCIE0);
UCSRB |= (1<<RXEN) | (1<<RXCIE);
}
@ -13,5 +13,5 @@ void __attribute__ ((naked)) __attribute__ ((section (".init8"))) uart_rx_sei()
}
ISR(USART_RX_vect) {
uart_process(UDR0);
uart_process(UDR);
}

View File

@ -4,10 +4,10 @@
#include <avr/interrupt.h>
void __attribute__ ((naked)) __attribute__ ((section (".init6"))) uart_tx_init() {
UCSR0B |= (1<<TXEN0);
UCSRB |= (1<<TXEN);
}
void uart_putc(unsigned char c) {
while( ( UCSR0A & ( 1 << UDRE0 ) ) == 0 ) {}
UDR0 = c;
while( ( UCSRA & ( 1 << UDRE ) ) == 0 ) {}
UDR = c;
}