From e9a73bbb3c14af340999f70146747787785f4fee Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 19 Dec 2011 18:20:33 +0000 Subject: initial commit --- avr_libs/uartlib/group__pfleury__uart.html | 560 +++++++++++++++++++++++++++++ 1 file changed, 560 insertions(+) create mode 100644 avr_libs/uartlib/group__pfleury__uart.html (limited to 'avr_libs/uartlib/group__pfleury__uart.html') diff --git a/avr_libs/uartlib/group__pfleury__uart.html b/avr_libs/uartlib/group__pfleury__uart.html new file mode 100644 index 0000000..7ab9c45 --- /dev/null +++ b/avr_libs/uartlib/group__pfleury__uart.html @@ -0,0 +1,560 @@ + + +AVR-GCC libraries: UART Library + + + +

UART Library


Detailed Description

+Interrupt UART library using the built-in UART with transmit and receive circular buffers. +

+

 #include <uart.h> 
+

+This library can be used to transmit and receive data through the built in UART.

+An interrupt is generated when the UART has finished transmitting or receiving a byte. The interrupt handling routines use circular buffers for buffering received and transmitted data.

+The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants define the size of the circular buffers in bytes. Note that these constants must be a power of 2. You may need to adapt this constants to your target and your application by adding CDEFS += -DUART_RX_BUFFER_SIZE=nn -DUART_RX_BUFFER_SIZE=nn to your Makefile.

+

Note:
Based on Atmel Application Note AVR306
+
Author:
Peter Fleury pfleury@gmx.ch http://jump.to/fleury
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Defines

#define UART_BAUD_SELECT(baudRate, xtalCpu)   ((xtalCpu)/((baudRate)*16l)-1)
 UART Baudrate Expression.
#define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate, xtalCpu)   (((xtalCpu)/((baudRate)*8l)-1)|0x8000)
 UART Baudrate Expression for ATmega double speed mode.
#define UART_RX_BUFFER_SIZE   32
#define UART_TX_BUFFER_SIZE   32
+#define UART_FRAME_ERROR   0x0800
+#define UART_OVERRUN_ERROR   0x0400
+#define UART_BUFFER_OVERFLOW   0x0200
+#define UART_NO_DATA   0x0100
+#define uart_puts_P(__s)   uart_puts_p(PSTR(__s))
 Macro to automatically put a string constant into program memory.
+#define uart1_puts_P(__s)   uart1_puts_p(PSTR(__s))
 Macro to automatically put a string constant into program memory.

Functions

void uart_init (unsigned int baudrate)
 Initialize UART and set baudrate.
unsigned int uart_getc (void)
 Get received byte from ringbuffer.
void uart_putc (unsigned char data)
 Put byte to ringbuffer for transmitting via UART.
void uart_puts (const char *s)
 Put string to ringbuffer for transmitting via UART.
void uart_puts_p (const char *s)
 Put string from program memory to ringbuffer for transmitting via UART.
void uart1_init (unsigned int baudrate)
 Initialize USART1 (only available on selected ATmegas).
unsigned int uart1_getc (void)
 Get received byte of USART1 from ringbuffer. (only available on selected ATmega).
void uart1_putc (unsigned char data)
 Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega).
void uart1_puts (const char *s)
 Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega).
void uart1_puts_p (const char *s)
 Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega).
+


Define Documentation

+

+ + + + +
+ + + + + + + + + + + + +
#define UART_BAUD_SELECT baudRate,
xtalCpu   )    ((xtalCpu)/((baudRate)*16l)-1)
+
+ + + + + +
+   + + +

+UART Baudrate Expression. +

+

Parameters:
+ + + +
xtalcpu system clock in Mhz, e.g. 4000000L for 4Mhz
baudrate baudrate in bps, e.g. 1200, 2400, 9600
+
+
+

+ + + + +
+ + + + + + + + + + + + +
#define UART_BAUD_SELECT_DOUBLE_SPEED baudRate,
xtalCpu   )    (((xtalCpu)/((baudRate)*8l)-1)|0x8000)
+
+ + + + + +
+   + + +

+UART Baudrate Expression for ATmega double speed mode. +

+

Parameters:
+ + + +
xtalcpu system clock in Mhz, e.g. 4000000L for 4Mhz
baudrate baudrate in bps, e.g. 1200, 2400, 9600
+
+
+

+ + + + +
+ + + + +
#define UART_RX_BUFFER_SIZE   32
+
+ + + + + +
+   + + +

+Size of the circular receive buffer, must be power of 2

+

+ + + + +
+ + + + +
#define UART_TX_BUFFER_SIZE   32
+
+ + + + + +
+   + + +

+Size of the circular transmit buffer, must be power of 2

+


Function Documentation

+

+ + + + +
+ + + + + + + + + +
void uart_init unsigned int  baudrate  ) 
+
+ + + + + +
+   + + +

+Initialize UART and set baudrate. +

+

Parameters:
+ + +
baudrate Specify baudrate using macro UART_BAUD_SELECT()
+
+
Returns:
none
+
+

+ + + + +
+ + + + + + + + + +
unsigned int uart_getc void   ) 
+
+ + + + + +
+   + + +

+Get received byte from ringbuffer. +

+Returns in the lower byte the received character and in the higher byte the last receive error. UART_NO_DATA is returned when no data is available.

+

Parameters:
+ + +
void 
+
+
Returns:
lower byte: received byte from ringbuffer

+higher byte: last receive status

    +
  • 0 successfully received data from UART
  • UART_NO_DATA
    +no receive data available
  • UART_BUFFER_OVERFLOW
    +Receive ringbuffer overflow. We are not reading the receive buffer fast enough, one or more received character have been dropped
  • UART_OVERRUN_ERROR
    +Overrun condition by UART. A character already present in the UART UDR register was not read by the interrupt handler before the next character arrived, one or more received characters have been dropped.
  • UART_FRAME_ERROR
    +Framing Error by UART
+
+
+

+ + + + +
+ + + + + + + + + +
void uart_putc unsigned char  data  ) 
+
+ + + + + +
+   + + +

+Put byte to ringbuffer for transmitting via UART. +

+

Parameters:
+ + +
data byte to be transmitted
+
+
Returns:
none
+
+

+ + + + +
+ + + + + + + + + +
void uart_puts const char *  s  ) 
+
+ + + + + +
+   + + +

+Put string to ringbuffer for transmitting via UART. +

+The string is buffered by the uart library in a circular buffer and one character at a time is transmitted to the UART using interrupts. Blocks if it can not write the whole string into the circular buffer.

+

Parameters:
+ + +
s string to be transmitted
+
+
Returns:
none
+
+

+ + + + +
+ + + + + + + + + +
void uart_puts_p const char *  s  ) 
+
+ + + + + +
+   + + +

+Put string from program memory to ringbuffer for transmitting via UART. +

+The string is buffered by the uart library in a circular buffer and one character at a time is transmitted to the UART using interrupts. Blocks if it can not write the whole string into the circular buffer.

+

Parameters:
+ + +
s program memory string to be transmitted
+
+
Returns:
none
+
See also:
uart_puts_P
+
+

+ + + + +
+ + + + + + + + + +
void uart1_init unsigned int  baudrate  ) 
+
+ + + + + +
+   + + +

+Initialize USART1 (only available on selected ATmegas). +

+

See also:
uart_init
+
+

+ + + + +
+ + + + + + + + + +
unsigned int uart1_getc void   ) 
+
+ + + + + +
+   + + +

+Get received byte of USART1 from ringbuffer. (only available on selected ATmega). +

+

See also:
uart_getc
+
+

+ + + + +
+ + + + + + + + + +
void uart1_putc unsigned char  data  ) 
+
+ + + + + +
+   + + +

+Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega). +

+

See also:
uart_putc
+
+

+ + + + +
+ + + + + + + + + +
void uart1_puts const char *  s  ) 
+
+ + + + + +
+   + + +

+Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega). +

+

See also:
uart_puts
+
+

+ + + + +
+ + + + + + + + + +
void uart1_puts_p const char *  s  ) 
+
+ + + + + +
+   + + +

+Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega). +

+

See also:
uart_puts_p
+
+


Generated on Sun Jul 10 13:47:45 2005 for AVR-GCC libraries by  + +doxygen 1.4.1
+ + -- cgit v1.2.3