Skip to content

Commit 2e377e8

Browse files
committed
Add proper readme.md
1 parent e59fd74 commit 2e377e8

File tree

1 file changed

+188
-1
lines changed

1 file changed

+188
-1
lines changed

README.md

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,188 @@
1-
avr-tinyuart
1+
<h1 align="center" style="font-weight: bold; margin-top: 20px; margin-bottom: 20px;">avr-tinyuart</h1>
2+
3+
<h4 align="center">A software uart designed for tiny AVR MCUs.</h4>
4+
5+
<p align="center">
6+
<a href="#changelog"><img src="https://img.shields.io/github/release-pre/nqtronix/avr-tinyuart.svg" alt="release: NA"></a>
7+
<a href="#about"><img src="https://img.shields.io/badge/language-C_(GCC_5.4.0)-blue.svg" alt="language: C GCC (5.4.0)"></a>
8+
<a href="#about"><img src="https://img.shields.io/badge/platform-AVR8-blue.svg" alt="platform: AVR8"></a>
9+
<a href="#about"><img src="https://img.shields.io/badge/status-maintained-green.svg" alt="status: maintained"></a>
10+
<a href="https://github.com/nqtronix/avr-tinyuart/issues"><img src="https://img.shields.io/github/issues/nqtronix/avr-tinyuart.svg" alt="issues: NA"></a>
11+
<a href="#license"><img src="https://img.shields.io/github/license/nqtronix/avr-tinyuart.svg" alt="license: NA"></a>
12+
</p>
13+
14+
<p align="center">
15+
<a href="#getting-started">Getting Started</a> •
16+
<a href="#under-the-hood">Under the Hood</a> •
17+
<a href="#support">Need Help?</a> •
18+
<a href="#about">About</a> •
19+
<a href="#credits-and-references">Credits</a>
20+
</p>
21+
22+
23+
24+
## Introduction
25+
It can be surprisingly difficult to debug the smallest MCUs of the AVR family - the basic programming interfaces and limited IO make it hard to get real-time information about what your code does.
26+
27+
**avr-tinyuart** provides a simple yet highly optimized uart tx function. It can be used to print any information to a terminal or to correlate the data with analog signals on an oscilloscope. The *tiny* footprint makes it suitable for almost any project.
28+
29+
<br>
30+
31+
## Key Features
32+
33+
- **software only:** no UART, timer or interrupt required
34+
- **lightweight:** uint8_t tx function compiles to as little as 34 bytes flash
35+
- **flexible:** defines set baud rate, IO and options
36+
- **accurate:** bit delays accurate to ±0.5 cycles
37+
38+
<br>
39+
40+
## Limitations
41+
42+
- The algorithm uses the PIN register to toggle the TX output efficiently. This feature is not available on some older AVRs.
43+
- The maximum bit-delay is about 768 cycles. This limits the *maximum* cpu clock for a given baud rate: 7372800Hz for 9600baud; 14745600Hz for 19200baud
44+
- There is no receive funtion as it would be significantly more complex and was not needed at the time of writing.
45+
46+
<br>
47+
48+
## Usage Example
49+
**avr-tinyuart** is trivial to use. Just call `tinyuart_init()` to init the output and `tinyuart_send_uint8()` whenever you want so send some data.
50+
51+
```c
52+
int main(void)
53+
{
54+
tinyuart_init();
55+
56+
// interrupts must be disbaled before calling the function
57+
cli();
58+
59+
// send ASCII
60+
tinyuart_send_uint8('H');
61+
tinyuart_send_uint8('i');
62+
tinyuart_send_uint8('\r');
63+
tinyuart_send_uint8('\n');
64+
65+
// send numbers
66+
tinyuart_send_uint8(0);
67+
tinyuart_send_uint8(0xff);
68+
69+
// re-enable interrups (if needed by your code)
70+
sei();
71+
72+
while (1);
73+
}
74+
```
75+
76+
<br>
77+
78+
## Getting Started
79+
This section is written especially for everyone who is **not familiar** with the used tools. If you run into problems, please [ask for clarification](#get-help).<br>
80+
81+
### Step 0: Software
82+
- [**Atmel Studio 7.0**][tool-atmel-studio-7-0] (Build 1931) [free]<br>
83+
The installer contains all tools you need to open, edit, compile, simulate and flash this code. If you favor another development tool, feel free to use it instead. (But please understand that I can not provide any support).
84+
85+
### Step 1: Download avr-tinyuart
86+
- Clone this repository or hit [Download][git-download] and extract the .zip file.
87+
88+
### Step 2: Browse the project
89+
- **Open the project in Atmel Studio:**<br>
90+
Either double click `tinyuart.atsln` or open Atmel Studio and select "File -> Open -> Project/Solution..."
91+
92+
### Step 3: Run the demo
93+
- **Select your MCU & Programming tool:**<br>
94+
Press `ALT + F7`; select your MCU under `Device` and `Change Device...` and your tool under `Tool` and pick it from the drop down menu
95+
96+
- **Adjust settings:**<br>
97+
Open `tinyuart.h` and adjust the settings as needed. By default it's configured for an ATTINY13A running at 9.6MHz and 115200 baud.
98+
99+
- **Compile & Program:**<br>
100+
Press `CTRL + ALT + F5` to compile a new version for your settings and flash it afterwards.
101+
102+
<br>
103+
104+
## Under the Hood
105+
106+
In theory any software UART implementation is quite simple, just output the correct bit at the right time. To archive this, the following tricks are noteworthy:
107+
108+
1. The code uses a toggle pattern instead of the data, this way high and low outputs can be generated with ony one instruction. This makes the timing independent of the data being send.
109+
2. The carry bit is used as a 9th bit to hold the stop-bit which is later accessed with the `ror` instruction. This ensures the timing of the stop-bit is identical and also saves a few bytes code.
110+
3. The delays are calculated by the C preprocessor. It does not support floating point, so to round a value `(n*2+1)/2` is used.
111+
112+
113+
<br>
114+
115+
## Support
116+
117+
### FAQ
118+
119+
- **Q: I've followed the getting started steps but the terminal shows only garbage! Why?**<br>
120+
A: Because UART does not have a dedicated clock line, it requires a fairly accurate clock of both sender and receiver. The total acceptable error is ≈ ±4.5%, but the RC oscillator within most AVRs is only specified within ±10%. It can be calibrated, but it's easier to tweak `TINYUART_F_CPU` and let the code deal with the difference. UART to USB convertes typically use a crystal and thus have a low tolerance (±20ppm = ±0.002%); the delay code has an error of ±0.5 cycles or <0.6% with default settings.
121+
122+
123+
### Get Help
124+
125+
**Something doesn't work as expected?** No worries! Just open up a new issue in the [GitHub issue tracker][git-issues]. Please provide all information to reproduce your problem. If you don't have a GitHub account (and can't be bothered to create one,) you can [contact](#contact) me directly.
126+
127+
<br>
128+
129+
### Contribute
130+
131+
**Spotted an error?** [Open an issue][git-issues] or submit a pull request.
132+
133+
There is no CONTRIBUTING.md yet, sorry. Contributions will inherit the [license](#license) of this project. If you have any questions, just ask.
134+
135+
<br>
136+
137+
## About
138+
### Status
139+
**This project is currently classified as** <a href="https://github.com/nqtronix/git-template/blob/master/badges.md#project-status"><img src="https://img.shields.io/badge/status-maintained-green.svg" alt="status: maintained"></a><br>
140+
_The developers intend to keep the code in working condition by updating dependencies, fixing bugs and solving issues._
141+
142+
As my testing needs increase I will likely add the functionality I need.
143+
144+
<br>
145+
146+
### Changelog
147+
This project uses [**Semantic Versioning 2.0.0**][semver.org]. During initial development (0.x.x versions) any _major_ increase is substituted with a _minor_ increase (0.1.0->0.2.0 instead of 0.1.0->1.0.0).
148+
149+
The message of each commit contains detailed information about the changes made. The list below is a summary about all significant improvements.
150+
151+
- **0.1.0 (latest)** <br>
152+
- initial release
153+
154+
<br>
155+
156+
### Contact
157+
158+
If you haven't done so already, please check out [Get Help](#get-help) for the fastest possible help on your issue. Alternatively you can find my public email address on my [profile][git-profile].
159+
160+
<br>
161+
162+
## Credits and References
163+
164+
### Projects Used
165+
- [**git-template**][git-repo-git-template] - _A simple and clean git repository template._<br>
166+
167+
<br>
168+
169+
170+
## License
171+
This project is proudly licensed under the [MIT license][git-license].
172+
173+
The MIT license was chosen to give you the freedom to use this project in any way you want, while protecting all contributors from legal claims. Good code works, great code works for everyone. If this code has become a part of one of your projects, a link back to us would be highly appreciated. Thanks!
174+
175+
<!-- Links -->
176+
177+
[git-readme]:README.md
178+
[git-license]:LICENSE.md
179+
[git-profile]:https://github.com/nqtronix
180+
[git-issues]:https://github.com/nqtronix/unittrace/issues
181+
[git-download]:https://github.com/nqtronix/unittrace/archive/master.zip
182+
183+
[git-repo-git-template]:https://github.com/nqtronix/git-template
184+
185+
[semver.org]:semver.org
186+
187+
[tool-atmel-studio-7-0]:https://www.microchip.com/mplab/avr-support/atmel-studio-7
188+

0 commit comments

Comments
 (0)