Close

Serial Communications

A project log for 65c02 Homebrew Computer on breadboard

Custom designed breadboard computer (BBC!) with bespoke programming language, full graphics, sound and SD card storage.

6502nerd6502Nerd 05/24/2015 at 13:433 Comments

Serial Input / Output

One of the key methods of input and output with my home brew is serial communications to and from my development machine (a modern Windows 10 laptop).

The serial commmunication protocols I remember from in the 80s and early 90s was RS-232. I naively thought this would be the thing to use now. However, my development machine does not have serial ports - USB is now the only serial methods I have at my disposal.

A bit of research revealed that direct USB to homebrew connectivity would be difficult (at least for me) to achieve. However, the popularity of kit like Arduino and Raspberry Pi have helped the proliferation of USB to serial cables with built in adapters. I purchased a very cheap one off ebay. It means that when connected to my dev machine, an additional COM port in Windows is available, through which I can use a terminal emulator. On the homebrew side, the cable presents 4 pins : +5V, GND, Serial Out, Serial In. This means I also have the ability to power my homebrew off the 5V supply rather than using my home-made 5V supply (interesting mini-project, but clunky).

My original serial comms was designed around using the SP pin on each of the two CIAs for input and output. However, it required a fairly software intensive set up to drive and I wasn't happy with the reliability of it. Plus, I wanted to use the CIA lines for other expansion options.

So I added a CMD 65c51 ACIA. This is a fairly simple to operate serial input/output device, and being part of the MOS family, easy to interface to the 6502. I will keep the rest of this section for historic purposes.

The software programming of the CIA was simple and it was easy to update the few low level I/O routines. However, it still took me ages to get it working because the ACIA needs a 1.8432Mhz clock. As this is not a muliple of my 21.7MHz, it needed it's own clock circuit.

So I obtained an appropriate crystal and wired up a 7404 using a circuit diagram off the internet. I checked it with the scope and it looked like the circuit was putting out a clean 1.8432MHz square wave. However the ACIA was not working, no matter what I did. I then noticed some unusual behaviour - for example if my finger touched the crystal, suddenly the ACIA would work and continue to work. Even putting my hand near the ACIA seemed to kick it in to life - very, very weird.

I put it down to the clock generator circuit. I have not spent any time trying to understand the most analogue part of the home brew which is the clock generators using piezo effects generated by crystals. So I had no idea what to do, but after further searching found an alternative circuit which starts up without requiring the touch of a finger or a magic wave of the hand!!

Old CIA based Serial

The two 6526 CIAs in the system provide serial communications. Even though each CIA has a SP pin for serial input or output, the USB to serial adapter I am using has a dedicated pins for send and receive. I wasn't sure how to wire up a single SP to two pins on the serial interface, so I decided to use one 6525 for input and the other for output.

Serial Input

I started with designing serial input. The mode of operation is as follows:

The software to run this is fairly simple. In pseudo code it looks like this:

One slight complication - the CIA expects data to be shifted in from MSB to LSB (i.e. shifting right each time). It turns out the USB to serial adapter does it the other way. So the final step is to shift the SDR LSB first in to the translated byte MSB first.

The Timer A countdown is clocked by Phi2, which is 2,684,659Hz. This means one clock cycle is approximately 0.3725 of a microsecond. To clock serial data in at 9600 baud (bits per second) means that each bit is approximately 104 microseconds. Half a bit time is 52 microseconds. Therefore Timer A needs to be set to 140 (52/0.3725, rounded to the nearest whole).

Serial Output

Output is done on the second CIA, and the mode of operation is even simpler than input:

Discussions

6502Nerd wrote 11/19/2015 at 18:12 point

In light of my recent corrections to the way I do address decoding and device selection, I have to admit now that the reason the WDC 65c51 did not work is very likely because I was not addressing it correctly.  Yes the part has bugs, but the issue I had was getting no response from the device.  The CMD 65c51 worked, but it clearly was tolerating my decoding bug, it really should also have not worked!  Anyway, I am now tempted to use the WDC part as it will clock much higher than the CMD - it means I might be able to turn the clock up to 5.4Mhz! ;-)  But I have other things to do before that...

  Are you sure? yes | no

6502Nerd wrote 06/23/2015 at 21:16 point

Ok I used a different ACIA part, with no luck.  However, one of the problems was the clock circuit for the 1.8432MHz signal.  It's working now, but boy the analogue side of electronics feels like black magic sometimes!

  Are you sure? yes | no

6502Nerd wrote 06/14/2015 at 12:14 point

Wow, I spent several days trying to get the WDC 65c51 ACIA to work. The reason is that my serial I/O approach below is a bit Heath-Robinson and not very efficient as the CPU has to block on I/O anddisable interrupts to make sure no bits are lost. So I bought the 65c51 off ebay and got to work. After nothing working properly, did some research and found that people had loads of issues with the WDC part. Not only that the WDC datasheet is ridiculous for example, here is a sample of the errata section: "Initial Transmit Shift Register.
After reading the receive register, determining that the transmit data register is empty and sending a stream of characters to the transmit data register, the initial one or two writes to thetransmitter may intermittently shift incorrectly depending on the circuit design used. This issue was evident on the previous sample. A possible solution to this would be to send an additional two characters that will be ignored upon receipt"

 
I would love to know how WDC think I can control the software of the outside world to ignore an addition 2 characters. 


I will come back to this part of the system at a later date as I do want to improve the serial capabilities.

  Are you sure? yes | no