Fix error in AVRISP programmer when repeatedly using PDI mode via the hardware USART...
[pub/USBasp.git] / Projects / AVRISP / Lib / PDITarget.c
index c774fda..28df550 100644 (file)
@@ -102,7 +102,7 @@ void PDITarget_EnableTargetPDI(void)
        \r
        /* Set up the synchronous USART for XMEGA communications - \r
           8 data bits, even parity, 2 stop bits */\r
-       UBRR1  = 10;\r
+       UBRR1  = (F_CPU / 1000000UL);\r
        UCSR1B = (1 << TXEN1);\r
        UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);\r
 \r
@@ -167,15 +167,16 @@ void PDITarget_SendByte(uint8_t Byte)
                PORTD  |=  (1 << 3);\r
                DDRD   |=  (1 << 3);\r
 \r
-               UCSR1B &= ~(1 << RXEN1);\r
                UCSR1B |=  (1 << TXEN1);\r
+               UCSR1B &= ~(1 << RXEN1);\r
                \r
                IsSending = true;\r
        }\r
        \r
        /* Wait until there is space in the hardware Tx buffer before writing */\r
        while (!(UCSR1A & (1 << UDRE1)));\r
-       UDR1 = Byte;\r
+       UCSR1A |= (1 << TXC1);\r
+       UDR1    = Byte;\r
 #else\r
        /* Switch to Tx mode if currently in Rx mode */\r
        if (!(IsSending))\r