1. Trammell Hudson
  2. teletype

Commits

Trammell Hudson  committed 103e428

ASR33 works with hardware uart, but needs massive cleanup

  • Participants
  • Parent commits 16b5980
  • Branches default

Comments (0)

Files changed (2)

File Makefile

View file
  • Ignore whitespace
 #   so your program will run at the correct speed.  You should also set this
 #   variable to same clock speed.  The _delay_ms() macro uses this, and many
 #   examples use this variable to calculate timings.  Do not add a "UL" here.
-F_CPU = 8000000
+F_CPU = 4000000
 
 
 # Output format. (can be srec, ihex, binary)

File asr33.c

View file
  • Ignore whitespace
 /**
  * \file 110 current loop interface for an ASR33
+ *
+ * ASR33 Wiring:   Teensy Wiring
+ * TX+ == Green    Vcc
+ * TX- == Red      PD2 (RXD1), tie to ground via 330 Ohm
+ * RX+ == Brown    PD3 (TXD1)
+ * RX- == Yellow   330 Ohm resistor to ground
+ *
+ * Teensy clock 4 MHz
+ * UBRR1 = 2272
+ * UCSR1C = | (1 << UPM11) // even parity
+ *          | (0 << UPM10)
+ *          | (0 << UCSZ12) // 7 data bits
+ *          | (1 << UCSZ11)
+ *          | (0 << UCSZ10)
+ *          | (1 << USBS1) // 2 stop bits
  */
 
 #include <avr/io.h>
 }
 
 //#define TTY_RX 0xD2
-#define TTY_RX 0xF7
+#define TTY_RX 0xD2
 #define TTY_TX 0xD3
 #define TTY_DEBUG 0xD7
 #define BIT_CLOCK 9090
 	uint8_t c
 )
 {
+#if 0
 	// start bit
 	out(TTY_TX, 1);
 
 	out(TTY_TX, 0);
 	_delay_us(BIT_CLOCK);
 	_delay_us(BIT_CLOCK);
+#else
+	while (bit_is_clear(UCSR1A, UDRE1))
+		;
+	UDR1 = c;
+#endif
 }
 
 
 
 int main(void)
 {
-	// set for 16 MHz clock
+	// set for 4 MHz clock
 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
-	CPU_PRESCALE(0);
+	CPU_PRESCALE(2);
 
 	// Disable the ADC
 	ADMUX = 0;
 	adc_init();
 
 	ddr(TTY_TX, 1);
-	out(TTY_TX, 0); // pull low against resistor
+	out(TTY_TX, 0); // pull down
 
 	// D2 is used for input (since it is also a UART)
 	// it has an external pull up resistor to +5v
 	ddr(TTY_DEBUG, 1);
 	ddr(TTY_DEBUG, 1);
 
-#if 0
+#define CONFIG_ASR33_UART
+#ifdef CONFIG_ASR33_UART
 	// 110 E72 is too SLOW at 16 MHz.  Wow.
-	// bit banging it is...
-	UBRR0 = ;
-	UCSR0B = (1 << RXEN0);
-	UCSR0C = 0
+	// UBRR is 12 bits, max 4096.  So we run at 4 MHz
+	// to keep UBRR0 in range.
+	UBRR1 = 2272;
+	UCSR1B = 0
+		| (1 << RXEN1)
+		| (1 << TXEN1)
+		;
+
+	UCSR1C = 0
 		| (1 << UPM11) // even parity
 		| (0 << UPM10)
 		| (0 << UCSZ12) // 7 data bits
 			out(0xD6, 0);
 		}
 
+#ifndef CONFIG_ASR33_UART
 		int x = in(TTY_RX);
 
 		// Wait for start bit
 
 		uint16_t byte = tty_in();
 #ifndef CONFIG_WAVEFORM
+#define CONFIG_DEBUG_BYTES
 #ifdef CONFIG_DEBUG_BYTES
 		usb_serial_putchar(hexdigit(byte >> 12));
 		usb_serial_putchar(hexdigit(byte >> 8));
 #endif
 		usb_serial_putchar((byte >> 2) & 0x7F);
 #endif
-		continue;
+#else
+		if (!bit_is_set(UCSR1A, RXC1))
+			continue;
 
+		uint8_t ch = UDR1;
+		usb_serial_putchar(ch);
+#endif
 	}
 }