1
1
//
2
2
// NeoSWSerial
3
+ // Copyright (C) 2015-2017, SlashDevin
4
+ //
5
+ // NeoSWSerial is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // NeoSWSerial is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU General Public License for more details:
14
+ //
15
+ // <http://www.gnu.org/licenses/>.
3
16
//
4
17
// Methods
5
18
// -------
16
29
// print() is supported
17
30
// =============================================================================
18
31
19
- #include " NeoSWSerial.h"
32
+ #include < NeoSWSerial.h>
20
33
21
34
// Default baud rate is 9600
22
35
static const uint8_t TICKS_PER_BIT_9600 = (uint8_t ) 26 ;
@@ -27,8 +40,17 @@ static const uint8_t BITS_PER_TICK_38400_Q10 = 157;
27
40
28
41
#if F_CPU == 16000000L
29
42
#define TCNTX TCNT0
43
+ #define PCI_FLAG_REGISTER PCIFR
30
44
#elif F_CPU == 8000000L
31
- #define TCNTX TCNT2
45
+ #if defined(__AVR_ATtiny25__) | \
46
+ defined (__AVR_ATtiny45__) | \
47
+ defined(__AVR_ATtiny85__)
48
+ #define TCNTX TCNT1
49
+ #define PCI_FLAG_REGISTER GIFR
50
+ #else
51
+ #define TCNTX TCNT2
52
+ #define PCI_FLAG_REGISTER PCIFR
53
+ #endif
32
54
#endif
33
55
34
56
static NeoSWSerial *listener = (NeoSWSerial *) NULL ;
@@ -121,8 +143,14 @@ void NeoSWSerial::listen()
121
143
122
144
if (F_CPU == 8000000L ) {
123
145
// Have to use timer 2 for an 8 MHz system.
124
- TCCR2A = 0x00 ;
125
- TCCR2B = 0x03 ; // divide by 32
146
+ #if defined(__AVR_ATtiny25__) | \
147
+ defined (__AVR_ATtiny45__) | \
148
+ defined (__AVR_ATtiny85__)
149
+ TCCR1 = 0x06 ; // divide by 32
150
+ #else
151
+ TCCR2A = 0x00 ;
152
+ TCCR2B = 0x03 ; // divide by 32
153
+ #endif
126
154
}
127
155
128
156
volatile uint8_t *pcmsk = digitalPinToPCMSK (rxPin);
@@ -507,8 +535,8 @@ size_t NeoSWSerial::write(uint8_t txChar)
507
535
508
536
while ((uint8_t )(TCNTX - t0) < width) {
509
537
// Receive interrupt pending?
510
- if (PCIFR & PCIbit) {
511
- PCIFR |= PCIbit; // clear it because...
538
+ if (PCI_FLAG_REGISTER & PCIbit) {
539
+ PCI_FLAG_REGISTER |= PCIbit; // clear it because...
512
540
rxISR ( *rxPort ); // ... this handles it
513
541
DBG_NSS_COUNT (polledPCI);
514
542
} else if (checkRxTime ()) {
0 commit comments