|
@@ -326,8 +326,15 @@ typedef union {
|
|
|
#define UART 0
|
|
|
#endif
|
|
|
|
|
|
+#ifdef SINGLESPEED
|
|
|
+/* Single speed option */
|
|
|
+#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 8L) / ((BAUD_RATE * 16L))) - 1 )
|
|
|
+#define BAUD_ACTUAL (F_CPU/(16 * ((BAUD_SETTING)+1)))
|
|
|
+#else
|
|
|
+/* Normal U2X usage */
|
|
|
#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 4L) / ((BAUD_RATE * 8L))) - 1 )
|
|
|
#define BAUD_ACTUAL (F_CPU/(8 * ((BAUD_SETTING)+1)))
|
|
|
+#endif
|
|
|
#if BAUD_ACTUAL <= BAUD_RATE
|
|
|
#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)
|
|
|
#if BAUD_ERROR >= 5
|
|
@@ -344,14 +351,14 @@ typedef union {
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
-#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
|
|
|
+#if BAUD_SETTING > 250
|
|
|
#error Unachievable baud rate (too slow) BAUD_RATE
|
|
|
#endif // baud rate slow check
|
|
|
-#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
|
|
|
+#if (BAUD_SETTING - 1) < 3
|
|
|
#if BAUD_ERROR != 0 // permit high bitrates (ie 1Mbps@16MHz) if error is zero
|
|
|
#error Unachievable baud rate (too fast) BAUD_RATE
|
|
|
#endif
|
|
|
-#endif // baud rate fastn check
|
|
|
+#endif // baud rate fast check
|
|
|
|
|
|
/* Watchdog settings */
|
|
|
#define WATCHDOG_OFF (0)
|
|
@@ -559,12 +566,16 @@ int main(void) {
|
|
|
|
|
|
#ifndef SOFT_UART
|
|
|
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega16__)
|
|
|
+#ifndef SINGLESPEED
|
|
|
UCSRA = _BV(U2X); //Double speed mode USART
|
|
|
+#endif
|
|
|
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
|
|
|
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
|
|
|
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
|
|
#else
|
|
|
+#ifndef SINGLESPEED
|
|
|
UART_SRA = _BV(U2X0); //Double speed mode USART0
|
|
|
+#endif
|
|
|
UART_SRB = _BV(RXEN0) | _BV(TXEN0);
|
|
|
UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
|
|
|
UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|