You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update of NeoHWSerial (https://github.com/SlashDevin/NeoHWSerial).
Changes:
- add required files for Arduino IDE >=v1.5.6
- renamed attachInterrupt()/detachInterrupt() to
attachRxInterrupt()/attachTxInterrupt()
- add attachTxInterrupt()/detachTxInterrupt() for user function on
Tx-empty interrupt. Useful e.g. for sync break handling in LIN bus
- call user Rx-ISR function with UART status byte. Useful e.g. for
sync break handling in LIN bus
- enable optional default action in user function via return value
Copy file name to clipboardExpand all lines: README.md
+17-11
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,32 @@
1
-
The **NeoHWSerial** class is a drop-in replacement for the Arduino built-in class `HardwareSerial`. It adds the capability to handle received characters with a user-defined function *during* the RX interrupt. This can improve performance significantly by eliminating all processing associated with storing and retrieving characters in the ring buffer **and** all polling code that constantly checked for new characters: `available` and `read` are unnecessary.
1
+
The **NeoHWSerial** class is a drop-in replacement for the Arduino built-in class `HardwareSerial`. It adds the capability to handle received characters with a user-defined function *during* the RX interrupt. This can improve performance significantly by eliminating all processing associated with storing and retrieving characters in the ring buffer **and** all polling code that constantly checked for new characters: `available` and `read` are unnecessary.
2
+
3
+
Note: This is a minor update of [NeoHWSerial by SlashDevin](https://github.com/SlashDevin/NeoHWSerial) for AVR. Changes:
4
+
- updated to Arduino IDE >=v1.5.6 library format (see [here](https://arduino.github.io/arduino-cli/latest/library-specification/))
5
+
- pass UART status byte to user receive function. Required e.g. for break detection in [LIN bus](https://en.wikipedia.org/wiki/Local_Interconnect_Network)
6
+
- support optional storing to ring buffer after return from user routine via return value
7
+
2
8
3
9
### Installation
4
10
5
11
1. Download the NeoHWSerial master zip file.
6
12
2. Extract all files into a tempory working directory.
7
-
3. Create a `NeoHWSerial` subdirectory in your `Arduino/Libraries` directory.
8
-
4. Copy all files from the version number subdirectory that corresponds to your IDE version into the `NeoHWSerial` subdirectory you created in step 1. For example, if you are using Arduino IDE version 1.0.5, copy all files from the extracted `NeoHWSerial-master/1.0.5` subdirectory into your `Arduino/Libraries/NeoHWSerial` subdirectory.
13
+
3. Create a `NeoHWSerial` subdirectory in your `Arduino/libraries` directory.
9
14
10
15
### Usage
11
16
12
17
To handle all received characters with your function, you must register it with the specific `NeoSerial[n]` instance:
13
18
14
19
#include <NeoHWSerial.h>
15
-
20
+
16
21
volatile uint32_t newlines = 0UL;
17
-
18
-
static void handleRxChar( uint8_t c )
22
+
23
+
static bool handleRxChar( uint8_t c, uint8_t status )
19
24
{
20
25
if (c == '\n')
21
26
newlines++;
27
+
return false; // don't store c in ring buffer
22
28
}
23
-
29
+
24
30
void setup()
25
31
{
26
32
NeoSerial1.attachInterrupt( handleRxChar );
@@ -29,14 +35,14 @@ To handle all received characters with your function, you must register it with
29
35
30
36
Remember that the registered function is called from an interrupt context, and it should return as quickly as possible. Taking too much time in the function will cause many unpredictable behaviors, including loss of received data. See the similar warnings for the built-in [`attachInterrupt`](https://www.arduino.cc/en/Reference/AttachInterrupt) for digital pins.
31
37
32
-
The registered function will be called from the ISR whenever a character is received. The received character **will not** be stored in the `rx_buffer`, and it **will not** be returned from `read()`. Any characters that were received and buffered before `attachInterrupt` was called remain in `rx_buffer`, and could be retrieved by calling `read()`.
38
+
The registered function will be called from the ISR whenever a character is received. The received character is stored in the `rx_buffer` after return from the user function, if the user function returns a _true_ value. Characters that were received and buffered before `attachInterrupt` was called remain in `rx_buffer`, and could be retrieved by calling `read()`.
33
39
34
40
If `attachInterrupt` is never called, or it is passed a `NULL` function, the normal buffering occurs, and all received characters must be obtained by calling `read()`.
35
41
36
42
The original `HardwareSerial` files were modified to include two new methods, `attachInterrupt` and `detachInterrupt`, and one new data member, the private `_isr`:
@@ -48,9 +54,9 @@ The original `HardwareSerial` files were modified to include two new methods, `a
48
54
49
55
To avoid name collisions, all `HardwareSerial` instances are prefixed with "Neo" in this replacement library. All parts of your sketch, including other libraries, must use
50
56
51
-
*`NeoSerial` instead of `Serial`,
57
+
*`NeoSerial` instead of `Serial`,
52
58
*`NeoSerial1` instead of `Serial1`,
53
-
*`NeoSerial2` instead of `Serial2`, and
59
+
*`NeoSerial2` instead of `Serial2`, and
54
60
*`NeoSerial3` instead of `Serial3`.
55
61
56
62
If there are any references to the original `HardwareSerial` instances, you will get one or more linker errors:
0 commit comments