From e4dec57da93141f92e8bc034a4c01ec80a61ded3 Mon Sep 17 00:00:00 2001 From: Christoph Schneeberger Date: Sun, 24 Mar 2019 14:38:24 +0100 Subject: [PATCH] sync --- README.md | 83 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 05ae87f..e3543de 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@ Use one include file to replace the Serial.print from Arduino library. [Using tabular data](#using-tabular-data) [How to switch from Arduino Serial](#howto-switch-from-arduino-serial) [Installation](#terser-installation) -[Using tabular data](#using-tabular-data) [TerSer Limitations](#terser-limitations) -[Code size and timing comparison](#code-size-and-timing-comparison) [Function reference](#function-reference) ### What is the problem with Arduino Serial.print ? @@ -27,34 +25,10 @@ It is admittedly very convenient to just use Serial.print(var); since it doesn't The TerSer.h offer the choice of 4 print format for numbers. Signed variables have a + or – sign in front. -| Normal (moz=0) | Spaces (moz=1) | Zeros (moz=2) | Compact (moz=3) | Serial.print | +| Normal (*moz=0*) | Spaces (*moz=1*) | Zeros (*moz=2*) | Compact (*moz=3*) | *Serial.print* | | -------------- | -------------- | -------------- | -------------- | -------------- | | ![moz0](docs/images/tab_moz0.png?raw=true "Example moz=0") | ![moz1](docs/images/tab_moz1.png?raw=true "Example moz=1") | ![moz2](docs/images/tab_moz2.png?raw=true "Example moz=2") | ![moz3](docs/images/tab_moz3.png?raw=true "Example moz=3") | ![Aserial](docs/images/tab_arduino_serial.png?raw=true "Example Arduino Serial.print") | - -### How to switch from Arduino Serial -If you are looking for a drop-in replacement for Arduino Serial with a smaller memory footprint follow the procedure outlined below to quickly switch your project to Didel TerSer: -* Add `#include ` at the top of your sketch or select the library from your Arduino IDE (*Sketch* | *Include Library*) -* Use the either the library function names we provide or define your own function names, for example: - `#define Serialprint(x) Text(x)` -* Search for all occurences or `Serial.print` and replace with `Serialprint` -Voila, you have switched to TerSer and enjoy smaller footprint at less mcu cycles - -#### Function aliasing -If you do not like our function/method names, feel free to define names that suit your tastes with i.e.: -`#define Serialprint(x) Text(x)` - -`#define Serialprint(x,BIN) Bin8(x)` - -`#define Serialprint(x,BIN) Bin16(x)` - -`#define Serialprint(x) Dec16(x)` - -etc. - -### TerSer Installation -Go to library manager in your Arduino IDE and search for 'TerSer'. - ### Example comparison between Didel TerSer and Arduino Serial | TerSer | Output TerSer | Output Serial | Arduino Serial | | ------------- | ------------- | ------------- | ------------- | @@ -84,8 +58,33 @@ HideZ();Dec8s(3); SetTab(15); ![Table1](docs/images/tabTable.png?raw=true "Example Table 1") -It is up to you to add functions like TextNL(); -if you need to keep your Serial.println() habits. + +### How to switch from Arduino Serial +If you are looking for a drop-in replacement for Arduino Serial with a smaller memory footprint follow the procedure outlined below to quickly switch your project to Didel TerSer: +* Add `#include ` at the top of your sketch or select the library from your Arduino IDE (*Sketch* | *Include Library*) +* Use the either the library function names we provide or define your own function names, for example: + `#define Serialprint(x) Text(x)` +* Search for all occurences or `Serial.print` and replace with `Serialprint` +Voila, you have switched to TerSer and enjoy smaller footprint at less mcu cycles + +#### Function aliasing +If you do not like our function/method names, feel free to define names that suit your tastes with i.e.: +`#define Serialprint(x) Text(x)` + +`#define Serialprint(x,BIN) Bin8(x)` + +`#define Serialprint(x,BIN) Bin16(x)` + +`#define Serialprint(x) Dec16(x)` + +etc. + +### TerSer Installation +Go to library manager in your Arduino IDE and search for 'TerSer'. + +Alternatively just download the TerSer.h into your sketch folder and include it with: + +`#include "TerSer.h"` ### TerSer Limitations @@ -96,9 +95,27 @@ Dec8(); and Dec16(); use a tricky macro to recognize the signed or unsigned data Code will be shorter and there will be no limitation if you use Dec8u(any unsigned expr); and Dec8s(any signed expr);, same of course Dec16u(); and Dec16s(); -### Code size and timing comparison -Code size has been obtained by calling one function at a time, compiler under the usual -0s mode. Size is the difference with the empty file size. TerSer.h can of course be used with setup() and loop(). It add the ~300 bytes Arduino initializations. -Execution time has been measured with a Nop replacing the SendCar function. The time depends on the baud rate, ~1 ms per character displayed at 9600 bits/s. +#### Baud rate +The baud rate is hardwired into TerSer.h and is by default set to 9600 bps. The serial speed is configured on the UBRR0 register. + +```void SetupTerSer() { + UBRR0= 103; // 9600 bits/s + UCSR0B=0x18; // -- -- -- rxe txe -- -- -- + UCSR0C=0x06; // set mode: 8 data bits, no parity, 1 stop bit``` + +If you need another baud rate than 9600 you can adjust the value in the TerSer.h according to the table below: + +| Baud rate | UBRR0 register *(@16MHz clock)* | +| ---------- | ---------- | +| 2400 | `UBRR0= 416;` | +| 4800 | `UBRR0= 207;` | +| **9600** | `UBRR0= 103;` *(default)* | +| 19200 | `UBRR0= 51;` | +| 38400 | `UBRR0= 25;` | +| 57600 | `UBRR0= 16;` | +| 115200 | `UBRR0= 6;` | + +For more information please see the [ATmega328 Datasheet](http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf) *(page 182)*. ### Function reference @@ -107,7 +124,7 @@ Execution time has been measured with a Nop replacing the SendCar function. The | Car(cc); | Send code cc to the UART | | cc=Get(); | Wait for a key depressed. Use Teraterm, too tricky with Arduino Terminal | | Text("abcd"); | Send the text and add a space | -|Textln("abcd"); | Same with CRLF | +| Textln("abcd"); | Same with CRLF | | CR(); | Send a CR-LF | | Bin8(v); | Display the 8 low bits of the variable v, converted to integers (all add a space) | | Bin16(v); | Display the 16 bits of the variable v, with a dot in the middle |