uart.h File Reference

UART. More...

#include "main.h"
#include "../libs/uartlibrary/uart.h"

Defines

#define UART_RX_BUFFER_SIZE   8
#define UART_TX_BUFFER_SIZE   8

Functions

void usart_init (void)
 initialises both USARTs
void usart_off (void)
 switches off both USARTs
void usart_baudrate (int8_t br)
 property: sets baudrate
void usart_setSync (int8_t enable)
 property: enables synchronous communication
void usart_stopBits (int8_t sb)
 property: sets the nr of stop bits
void usart_dataBits (int8_t db)
 property: sets the nr of data bits


Detailed Description

UART.

Serial communication.

Todo:
All the functions need to be completed.

Peter Fleury's lib?

ca 01 January 2006
Sven Kreiss

Define Documentation

#define UART_RX_BUFFER_SIZE   8
 

#define UART_TX_BUFFER_SIZE   8
 


Function Documentation

void usart_baudrate int8_t  br  ) 
 

property: sets baudrate

00052                                {
00053     uint16_t reg = 0;
00054 
00055     //all values for 11.0592MHz oscillator
00056     if     (br == 0) reg = 287; //2k4
00057     else if(br == 1) reg = 143; //4k8
00058     else if(br == 2) reg = 71; //9k6
00059     else if(br == 3) reg = 47; //14k4
00060     else if(br == 4) reg = 35; //19k2
00061     else if(br == 5) reg = 23; //28k8
00062     else if(br == 6) reg = 17; //38k4
00063     else if(br == 7) reg = 11; //57k6
00064     else if(br == 8) reg = 8; //76k8
00065     else if(br == 9) reg = 5; //115k2
00066     else if(br == 10) reg = 2; //230k4
00067 
00068     UBRR0H = ((reg>>8) & 255); UBRR0L = reg & 255;
00069     UBRR1H = ((reg>>8) & 255); UBRR1L = reg & 255;
00070 
00071 //  UBRR0H = 0; UBRR0L = 5;
00072 //  UBRR1H = 0; UBRR1L = 5;
00073 }

void usart_dataBits int8_t  db  ) 
 

property: sets the nr of data bits

00097                                {
00098     if     (db == 0){ UCSR0C |= (0<<UCSZ0); UCSR1C |= (0<<UCSZ1); } //5bits
00099     else if(db == 1){ UCSR0C |= (1<<UCSZ0); UCSR1C |= (1<<UCSZ1); } //6bits
00100     else if(db == 2){ UCSR0C |= (2<<UCSZ0); UCSR1C |= (2<<UCSZ1); } //7bits
00101     else if(db == 3){ UCSR0C |= (3<<UCSZ0); UCSR1C |= (3<<UCSZ1); } //8bits
00102     else if(db == 4){ UCSR0C |= (15<<UCSZ0); UCSR1C |= (15<<UCSZ1); } //9bits
00103 }

void usart_init void   ) 
 

initialises both USARTs

00017                       {
00018     //baudrate
00019 //  UBRR0H = 0; UBRR0L = 0;
00020 //  UBRR1H = 0; UBRR1L = 0;
00021     usart_baudrate(0);
00022 
00023     //erase data overflow flag
00024     UCSR0A &= ~(1<<DOR);
00025     UCSR1A &= ~(1<<DOR);
00026 
00027     //RXEN, TXEN, INTERRUPT ENABLE
00028     UCSR0B |= (1<<RXEN) | (1<<TXEN) | (1<<RXCIE);
00029     UCSR1B |= (1<<RXEN) | (1<<TXEN) | (1<<RXCIE);
00030 
00031     //2 stop bit, 8 data bit, synchronous mode
00032 //  UCSR0C = (1<<USBS) | (3<<UCSZ0);// | (1<<UMSEL);
00033 //  UCSR1C = (1<<USBS) | (3<<UCSZ0);// | (1<<UMSEL);
00034     usart_stopBits(1);
00035     usart_setSync(0);
00036     usart_dataBits(3);
00037 
00038     //activate internal PullUp for RX and XCK(if input)
00039     //DDRE = 255;
00040     PORTE |= (1<<PE0) | (1<<PE2);
00041     PORTD |= (1<<PD2) | (1<<PD5);
00042 
00043     uart_init(UART_BAUD_SELECT(9600, 11059200UL));
00044     uart1_init(UART_BAUD_SELECT(9600, 11059200UL));
00045 }

void usart_off void   ) 
 

switches off both USARTs

00047                      {
00048     UCSR0B &= ~(1<<RXEN) & ~(1<<TXEN);
00049     UCSR1B &= ~(1<<RXEN) & ~(1<<TXEN);
00050 }

void usart_setSync int8_t  enable  ) 
 

property: enables synchronous communication

00075                                   {
00076     if(enable == 1){    //sync enabled
00077         UCSR0C |= (1<<UMSEL);
00078         UCSR1C |= (1<<UMSEL);
00079     }
00080     else if(enable == 0){               //sync disabled
00081         UCSR0C &= ~(1<<UMSEL);
00082         UCSR1C &= ~(1<<UMSEL);
00083     }
00084 }

void usart_stopBits int8_t  sb  ) 
 

property: sets the nr of stop bits

00086                                {
00087     if(sb == 0){        //1 stop bit
00088         UCSR0C &= ~(1<<USBS);
00089         UCSR1C &= ~(1<<USBS);
00090     }
00091     else if(sb == 1){   //2 stop bits
00092         UCSR0C |= (1<<USBS);
00093         UCSR1C |= (1<<USBS);
00094     }
00095 }


Generated on Fri Aug 11 21:47:32 2006 for OpenOsci by  doxygen 1.4.6