avr-uart
AVR UART Library
README.md
1 avr-uart
2 ========
3 
4 An interrupt driven UART Library for 8-bit AVR microcontrollers
5 
6 Maintained by Andy Gock
7 
8 https://github.com/andygock/avr-uart
9 
10 Derived from original library by Peter Fleury.
11 
12 Interrupt driven UART library using the built-in UART with circular transmit and receive buffers.
13 
14 An interrupt is generated when the UART has finished transmitting or
15 receiving a byte. The interrupt handling routines use circular buffers
16 for buffering received and transmitted data.
17 
18 ## Setting up
19 
20 The `UART_RXn_BUFFER_SIZE` and `UART_TXn_BUFFER_SIZE` symbols define
21 the size of the circular buffers in bytes. These values **must be a power of 2**.
22 You may need to adapt this symbols to your target and your application by adding into your compiler options:
23 
24  -DUART_RXn_BUFFER_SIZE=nn -DUART_TXn_BUFFER_SIZE=nn
25 
26 `RXn` and `TXn` refer to the UART number, for UART3 with 128 byte buffers, add:
27 
28  -DUART_RX3_BUFFER_SIZE=128 -DUART_TX3_BUFFER_SIZE=128
29 
30 UART0 is always enabled by default, to enable the other available UARTs, add the following to your compiler's symbol options for the relevant UART (also known as USART) number.
31 
32  -DUSART1_ENABLED -DUSART2_ENABLED -DUSART3_ENABLED
33 
34 To enable large buffer support (over 256 bytes, up to 2^15 bytes) use:
35 
36  -DUSARTn_LARGE_BUFFER
37 
38 Where n = USART number. The maximum buffer size is 32768.
39 
40 This library supports AVR devices with up to 4 hardware USARTs.
41 
42 ### Compiler flags
43 
44 AVR/GNU C compiler requires the `-std=gnu99` flag.
45 
46 ## Documentation
47 
48 Doxygen based documentation can be viwed at:
49 
50 * HTML: <https://andygock.github.io/avr-uart-documentation/html/index.html>
51 * PDF: <https://andygock.github.io/avr-uart-documentation/latex/refman.pdf>
52 * RTF: <https://andygock.github.io/avr-uart-documentation/rtf/refman.rtf>
53 
54 ## Notes
55 
56 ### Buffer overflow behaviour
57 
58 When the RX circular buffer is full, and it receives further data from the UART, a buffer overflow condition occurs. Any new data is dropped. The RX buffer must be read before any more incoming data from the UART is placed into the RX buffer.
59 
60 If the TX buffer is full, and new data is sent to it using one of the `uartN_put*()` functions, this function will loop and wait until the buffer is not full any more. It is important to make sure you have not disabled your UART transmit interrupts (`TXEN*`) elsewhere in your application (e.g with `cli()`) before calling the `uartN_put*()` functions, as the application will lock up. The UART interrupts are automatically enabled when you use the `uartN_init()` functions. This is probably not the idea behaviour, I'll probably fix this some time.
61 
62 For now, make sure `TXEN*` interrupts are enabled when calling `uartN_put*()` functions. This should not be an issue unless you have code elsewhere purposely turning it off.