Fixed PDI/TPI programming speed of ~250KHz in the AVRISP-MKII Clone project, instead...
[pub/USBasp.git] / Projects / AVRISP-MKII / Lib / XPROG / XPROGTarget.c
index 2e52005..5d59f7f 100644 (file)
@@ -1,21 +1,21 @@
 /*
              LUFA Library
      Copyright (C) Dean Camera, 2010.
 /*
              LUFA Library
      Copyright (C) Dean Camera, 2010.
-              
+
   dean [at] fourwalledcubicle [dot] com
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
 */
 
 /*
   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
-  Permission to use, copy, modify, distribute, and sell this 
+  Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
   software and its documentation for any purpose is hereby granted
-  without fee, provided that the above copyright notice appear in 
+  without fee, provided that the above copyright notice appear in
   all copies and that both that the copyright notice and this
   all copies and that both that the copyright notice and this
-  permission notice and warranty disclaimer appear in supporting 
-  documentation, and that the name of the author not be used in 
-  advertising or publicity pertaining to distribution of the 
+  permission notice and warranty disclaimer appear in supporting
+  documentation, and that the name of the author not be used in
+  advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
   The author disclaim all warranties with regard to this
   software without specific, written prior permission.
 
   The author disclaim all warranties with regard to this
@@ -49,11 +49,11 @@ void XPROGTarget_EnableTargetPDI(void)
        /* Set Tx and XCK as outputs, Rx as input */
        DDRD |=  (1 << 5) | (1 << 3);
        DDRD &= ~(1 << 2);
        /* Set Tx and XCK as outputs, Rx as input */
        DDRD |=  (1 << 5) | (1 << 3);
        DDRD &= ~(1 << 2);
-       
+
        /* Set DATA line high for at least 90ns to disable /RESET functionality */
        PORTD |= (1 << 3);
        _delay_us(1);
        /* Set DATA line high for at least 90ns to disable /RESET functionality */
        PORTD |= (1 << 3);
        _delay_us(1);
-       
+
        /* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */
        UBRR1  = (F_CPU / XPROG_HARDWARE_SPEED);
        UCSR1B = (1 << TXEN1);
        /* Set up the synchronous USART for XMEGA communications - 8 data bits, even parity, 2 stop bits */
        UBRR1  = (F_CPU / XPROG_HARDWARE_SPEED);
        UCSR1B = (1 << TXEN1);
@@ -77,9 +77,9 @@ void XPROGTarget_EnableTargetTPI(void)
        /* Set Tx and XCK as outputs, Rx as input */
        DDRD |=  (1 << 5) | (1 << 3);
        DDRD &= ~(1 << 2);
        /* Set Tx and XCK as outputs, Rx as input */
        DDRD |=  (1 << 5) | (1 << 3);
        DDRD &= ~(1 << 2);
-               
+
        /* Set up the synchronous USART for TINY communications - 8 data bits, even parity, 2 stop bits */
        /* Set up the synchronous USART for TINY communications - 8 data bits, even parity, 2 stop bits */
-       UBRR1  = (F_CPU / XPROG_HARDWARE_SPEED);
+       UBRR1  = ((F_CPU / 2 / XPROG_HARDWARE_SPEED) - 1);
        UCSR1B = (1 << TXEN1);
        UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);
 
        UCSR1B = (1 << TXEN1);
        UCSR1C = (1 << UMSEL10) | (1 << UPM11) | (1 << USBS1) | (1 << UCSZ11) | (1 << UCSZ10) | (1 << UCPOL1);
 
@@ -133,7 +133,7 @@ void XPROGTarget_SendByte(const uint8_t Byte)
        /* Switch to Tx mode if currently in Rx mode */
        if (!(IsSending))
          XPROGTarget_SetTxMode();
        /* Switch to Tx mode if currently in Rx mode */
        if (!(IsSending))
          XPROGTarget_SetTxMode();
-         
+
        /* Wait until there is space in the hardware Tx buffer before writing */
        while (!(UCSR1A & (1 << UDRE1)));
        UCSR1A |= (1 << TXC1);
        /* Wait until there is space in the hardware Tx buffer before writing */
        while (!(UCSR1A & (1 << UDRE1)));
        UCSR1A |= (1 << TXC1);
@@ -202,3 +202,4 @@ static void XPROGTarget_SetRxMode(void)
 }
 
 #endif
 }
 
 #endif
+