diff options
Diffstat (limited to 'Projects/XPLAINBridge/Lib')
-rw-r--r-- | Projects/XPLAINBridge/Lib/SoftUART.c | 9 | ||||
-rw-r--r-- | Projects/XPLAINBridge/Lib/SoftUART.h | 12 |
2 files changed, 14 insertions, 7 deletions
diff --git a/Projects/XPLAINBridge/Lib/SoftUART.c b/Projects/XPLAINBridge/Lib/SoftUART.c index 4ec8dcdc8..8710722e4 100644 --- a/Projects/XPLAINBridge/Lib/SoftUART.c +++ b/Projects/XPLAINBridge/Lib/SoftUART.c @@ -63,12 +63,13 @@ void SoftUART_Init(void) EICRA = (1 << ISC01); EIMSK = (1 << INT0); - /* Set reception timer compare period and enable compare ISR */ - OCR1A = BIT_TIME; + /* Set the transmission and reception timer compare values for the default baud rate */ + SoftUART_SetBaud(9600); + + /* Setup reception timer compare ISR */ TIMSK1 = (1 << OCIE1A); - /* Set transmission timer compare period, enable compare ISR and start the timer */ - OCR3A = BIT_TIME; + /* Setup transmission timer compare ISR and start the timer */ TIMSK3 = (1 << OCIE3A); TCCR3B = ((1 << CS30) | (1 << WGM32)); } diff --git a/Projects/XPLAINBridge/Lib/SoftUART.h b/Projects/XPLAINBridge/Lib/SoftUART.h index a107d48a8..d0b03c04b 100644 --- a/Projects/XPLAINBridge/Lib/SoftUART.h +++ b/Projects/XPLAINBridge/Lib/SoftUART.h @@ -42,9 +42,6 @@ #include "LightweightRingBuff.h" /* Macros: */ - #define BAUD 9600 - #define BIT_TIME ((F_CPU / BAUD) - 1) - #define SRX PD0 #define SRXPIN PIND #define SRXPORT PORTD @@ -53,6 +50,15 @@ #define STXPORT PORTD #define STXDDR DDRD + /* Inline Functions: */ + static inline void SoftUART_SetBaud(const uint32_t Baud) + { + uint16_t BitTime = ((F_CPU / Baud) - 1); + + OCR1A = BitTime; + OCR3A = BitTime; + } + /* Function Prototypes: */ void SoftUART_Init(void); |