IsSending = true;\r
}\r
\r
- bool EvenParityBit = false;\r
- uint8_t ParityData = Byte;\r
+ /* Calculate the new USART frame data here while while we wait for a previous byte (if any) to finish sending */\r
+ uint16_t NewUSARTData = ((1 << 11) | (1 << 10) | (0 << 9) | ((uint16_t)Byte << 1) | (0 << 0));\r
\r
/* Compute Even parity - while a bit is still set, chop off lowest bit and toggle parity bit */\r
+ uint8_t ParityData = Byte;\r
while (ParityData)\r
{\r
- EvenParityBit ^= true;\r
- ParityData &= (ParityData - 1);\r
+ NewUSARTData ^= (1 << 9);\r
+ ParityData &= (ParityData - 1);\r
}\r
\r
- /* Calculate the new USART frame data here while while we wait for a previous byte (if any) to finish sending */\r
- uint16_t NewUSARTData = ((1 << 11) | (1 << 10) | ((uint16_t)EvenParityBit << 9) | ((uint16_t)Byte << 1) | (0 << 0));\r
-\r
+ /* Wait until transmitter is idle before writing new data */\r
while (SoftUSART_BitCount);\r
\r
/* Data shifted out LSB first, START DATA PARITY STOP STOP */\r
SoftUSART_BitCount = BITS_IN_FRAME;\r
while (SoftUSART_BitCount);\r
\r
- /* Throw away the start, parity and stop bits to leave only the data */\r
+ /* Throw away the parity and stop bits to leave only the data (start bit is already discarded) */\r
return (uint8_t)SoftUSART_Data;\r
#endif\r
}\r
}\r
\r
/* Need to do nothing for a full frame to send a BREAK */\r
- for (uint8_t i = 0; i <= BITS_IN_FRAME; i++)\r
+ for (uint8_t i = 0; i < BITS_IN_FRAME; i++)\r
{\r
/* Wait for a full cycle of the clock */\r
while (PIND & (1 << 5));\r