Seyed Masoud Hosseini · Overview · Study log · Ideas · Transcript · RSS feed
Embedded Systems, 6502 breadboard computer · Lecture 20 of 29 · 20:27
Lecture 20: 6502 Serial Interface
Study guide
What this lecture covers
The lecture completes a bidirectional RS-232 link for the breadboard 6502 computer. The previous videos showed how a charge pump multiplies voltage and how to receive RS-232 data with a single transistor; this one replaces that one-way hack with a MAX232 line driver chip and adds software to transmit data as well.
By the end, you can explain how the MAX232 generates RS-232 voltage levels from a single 5V supply, how to use the 6502's TSB/TRB instructions to toggle a single I/O pin, and why bit-banged serial communication ties up the processor and struggles with full-duplex operation.
Key ideas
- MAX232 chip: a dual driver/receiver with a built-in charge pump that converts a single 5V supply into RS-232-compliant positive and negative voltages, needing only external 1µF capacitors per the datasheet.
- RS-232 voltage spec and Postel's law: the standard defines anything above 3V (or below -3V) as valid, but the MAX232 transmits conservatively (around ±7V, guaranteed ±5V minimum) while accepting a wide, liberal range on receive — an example of "be conservative in what you send, liberal in what you accept."
- Simple wiring: the MAX232 needs only its charge-pump capacitors, power/ground, and the transmit/receive data lines connected between the 6522 VIA and the RS-232 connector; it handles all voltage translation internally.
- TSB and TRB instructions: "test and set bit" and "test and reset bit" let you set or clear a single bit of an I/O port using a mask in the accumulator, without disturbing the port's other bits.
- Transmit framing in software: sending a byte means pulling the line low for a start bit, shifting out 8 data bits with
RORand timed delays, then returning the line high for a stop bit. - Reused timing loop: the same calibrated bit-delay routine from the receive code (13 loop iterations for ~104 microseconds at 9,600 baud) is reused for transmit timing.
- Limitations of bit-banged serial: because the processor is fully occupied while sending or receiving bits, it cannot do anything else, cannot easily change baud rates, and cannot support true full-duplex operation.
Walkthrough
From a one-way MOSFET hack to a real level-shifter (0:00)
The lecture recaps the earlier videos: RS-232 needs roughly ±10V while the computer runs on 5V, and the previous receive-only solution used a MOSFET fed by the RS-232 signal. It introduces the MAX232 as a purpose-built chip that generates the needed voltages internally using a charge pump, avoiding the need to build one from discrete parts.
Reading the MAX232 datasheet against the RS-232 spec (2:01)
The lecture compares the MAX232's guaranteed output levels and receive thresholds against the TIA-232 standard's ±3V decision points, explaining Postel's robustness principle (conservative in sending, liberal in receiving) and noting that some cheap RS-232 products exploit the liberal receive range instead of following the spec properly.
Wiring the MAX232 into the circuit (5:05)
Following the datasheet pinout, the lecture connects power, ground, the four charge-pump capacitors, and swaps the previous receive circuit for the MAX232's receive path, confirming that receiving still works exactly as before with a much simpler, more robust circuit.
Adding the transmit path and TSB/TRB bit toggling (8:09)
The transmit side is wired from a 6522 I/O pin through the MAX232 to the RS-232 connector's transmit-data pin. The lecture explains TSB (OR a mask into a port, setting a bit) and TRB (AND an inverted mask into a port, clearing a bit) as clean ways to toggle a single output pin without disturbing the rest of the port.
Writing the transmit routine (13:13)
The lecture writes a subroutine that sends a start bit, loops 8 times using ROR to shift out each bit of a character from memory, uses TSB/TRB and the existing bit-delay timing to hold each bit for the correct duration, and finishes with a stop bit. Testing on the oscilloscope and a terminal program confirms both transmitting an asterisk and receiving typed characters work correctly.
Limitations of software-timed serial (18:15)
The lecture closes by pointing out that the delay-loop approach makes changing baud rates awkward and, more importantly, that the processor cannot do anything else — including receive — while it is busy transmitting, ruling out full-duplex operation. This motivates the next video's move to a dedicated UART chip that handles timing and bit-level transmission in hardware.
Before you watch
- The previous two videos in this series: the charge pump circuit and the MOSFET-based RS-232 receiver.
- Familiarity with 6502 assembly, rotate instructions, and the calibrated bit-delay timing technique.
- Basic understanding of the RS-232 frame format (start bit, data bits, stop bit).
Check your understanding
- Why does the MAX232 transmit at roughly ±7V rather than exactly the standard's ±3V threshold?
- What does the
TSBinstruction do differently from simply writing a fixed value to Port A? - Why can't the software in this lecture receive data at the same moment it is transmitting?
- What problem would arise if you tried to change the baud rate using this bit-banged approach?
Chapters
- 0:00 Introduction
- 1:23 Charge pumps
- 2:04 Max 232
- 9:50 Receiving
- 13:51 Sending
- 15:01 Sending a byte
- 16:41 Sending a character
From the YouTube description
Support these videos on Patreon: https://www.patreon.com/beneater or https://eater.net/support for other ways to support.
------------------
Social media:
Website: https://www.eater.net
Twitter: https://x.com/beneater
Patreon: https://patreon.com/beneater
Reddit: https://www.reddit.com/r/beneater
Special thanks to these supporters for making this video possible:
Adrien Friggeri, Aleksey Smolenchuk, Alex, Alex Black, An Dương, Anthony Weems, anula, Ben, Ben Cochran, Ben Williams, Bill Cooksey, Bill Watkins, Binh Tran, Богдан Федоров, Bradley Stach, BRian Haug, Burt Humburg, Carl Fooks, Carsten Schwender, Chai, Chris Anders, Chris Lajoie, Chris Sachs, criis, Cristi Cobzarenco, Daniel Jeppsson, Daniel Pink, Daniel Tang, Darrell Burgoon, Dave Walter, David Clark, David Cox, David Dawkins, David House, David Sastre Medina, David Turner, Dean Bevan, Dean Winger, Deep Kalra, Dennis Henderson, Dennis Schubert, Dilip Gowda, Dirk Sperling, Dmitry Guyvoronsky, Dušan Dželebdžić, Dustin Campbell, Dzevad Trumic, Emilio Mendoza, Eric Dynowski, Erik Broeders, Erik Granlund, Ethan Sifferman, Eugene Bulkin, Evan Serrano, Evan Thayer, Eveli László, EvinSaysMarxWasRight!, Florian Bürgi, fxshlein, George Miroshnykov, ghostdunk, GusGold, Hovis Biddle, Humberto Bruni, Ingo Eble, Ivan Esparza, Jack McCracken, Jacob Ford, James Beldock, James Capuder, Jared Dziedzic, Jason Bowen, Jason DeStefano, Jason Grim, Jason Thorpe, JavaXP, Jaxon Ketterman, jemmons, Jeremy Cole, Jesse Miller, Jim Kelly, Jim Knowler, Joe Beda, Joe Pregracke, Joe Rork, Joel Miller, Joey Murphy, John Hamberger jn., John Henning, John Meade, Jon Dugan, Jonn Miller, Joseph Portaro, Jurģis Brigmanis, Justin Graziani, Kai Wells, Kefen, Ken Paul, Kennard Smith, Kenneth Christensen, Kyle Kellogg, Lambda GPU Workstations, László Bácsi, Leo K, Lithou, Lord Dorogoth, Lukasz Pacholik, Marcos Fujisawa, Marcus Classon, Mariano Uvalle, Mark Day, Martin Noble, MatrixSenpai, Mats Fredriksson, Matt Krueger, Matthäus Pawelczyk, Matthew Clifford, melvin2001, Michael Koreshkov, MICHAEL SLASS, Michael Tedder, Michael Timbrook, Michael Weitman, Miguel Ríos, mikebad, Mikel Lindsaar, Miles Macchiaroli, Muqeet Mujahid, NacOJerk, Nate Welch, Nicholas Counts, Nicholas Moresco, Nick Chapman, Oli Homer, Ori Shamir, Örn Arnarson, Paul Heller, Paul Pluzhnikov, Pete Dietl, Phil Dennis, Philip Hofstetter, ProgrammerDor, Ralph Irons, Randal Masutani, Randy True, raoulvp, real_huitz, ReJ aka Renaldas Zioma, Ric King, Rick Hennigan, Robert Diaz, Robert Keown, Robey Pointer, Roland Munsil, Sagnik Bhattacharya, Scott Gorlick, Scott Holmes, Sean Patrick O’Brien, Sergey Kruk, Shane Mulcahy, SonOfSofaman, Spencer Ruport, Stefan Nesinger, Stephen Kovalcik, Stephen Riley, Steve Jones, TheWebMachine, Thomas Eriksen, Tim Oriol, Tim Walkowski, Tim Wheeler, Tom, Tom Knowles, Tom Smith, Tyler Latham, Usseod, Vincent Bernat, Warren Miller, Wim Coekaerts, xisente, Yee Lam Wan
← Lecture 19: Building a Voltage Multiplier · Lecture 21: RS232 Interface With the 6551 UART →
