Sunday 18 June 2023

Diagnosing IEC serial bus faults on the VIC20 and C64

One of the problems you get on Commodore machines is the dreaded "DEVICE NOT PRESENT" error, or just hanging up when trying to load.

That usually means either there is a problem with the C64/VIC20 or with the disk drive (or rarely the cable between). But it is difficult to know which.

Ideally, you have access to another drive or another Commodore machine to test with to narrow it down and identify the problem.

Because of the way the IEC serial bus is wired up, it is actually possible to get it to test itself, or at least some of it.

There are six signals on the IEC bus. One is ground, another is reset, so that leaves four we are interested in. One, ATN, is output only (ignore what it say above about in/out, that just means it is wired to a pin on the userport), another SRQ is input only (and only used on the C128/157x), and finally the two main signals, CLK and DAT, which are both inputs and outputs.

This post is written with the VIC20 in mind. Like any good Usborne programming book from the 1980s, there are notes at the end to convert it for the Commodore 64. 

The VIC20 schematic is a little difficult to follow. 

I have tried to tidy up the schematic by removing all but the relevant bits, and adding missing labels.

It's probably easier if I redraw it.

This shows the outputs go through a 7406 inverter gate, and then connect to the bus pin. The inputs are also connected to those bus pins, so you can effectively read back what is being written to the outputs (but note these is a stage of inversion, so write a 1, read a 0 and vice versa). This is a sort of a built in loop back. 

The 7406 is open collector, so it can only drive the bus low. There are pull up resistors for to pull the bus high when no devices are driving the bus low. All devices on the bus should be the same, so there can never be a bus conflict (at least electrically - there can still be logical conflicts, but that's for the protocol to deal with).

First, unplug any other devices, first, then write to the output and read back the input, and make sure it is correct.

You can do this with a series of POKE and PEEK commands. Whilst doing those, you can also monitor the signals on the port itself to check it is following along.

If all the values are correct, then it is unlikely to be any of the chips inside the machine at fault, and more likely the drive or the cabling / connectors in between.

You get dry joints on connector pins on joystick ports a lot, but I don't think I have seen that many on the IEC connectors.

If those values do not agree, it is either going to be one of the two VIA / CIA chips, or more often the 7406 driver chip (particularly when it is the MOS 7707 version).

You can trace through the schematic and see where the signal becomes stuck high or low.

All signals are active low, so that means the output of the IO chip is high, and the output of the 7406 inverter is low, and vice versa.

On the VIC20, type the following to activate ATN (remember these are active low)

POKE 37137, 128

And to turn it off use

POKE 37137, 0

It is a bit more complicated for CLK and DAT as they use handshaking pins which are multifunction.

The VIA PCR uses bits 1-3 for clock out, and 5-7 for data out. To control them manually, bits 2,3,6 and 7 are all high, so bits 1 and 5 control the values.

POKE 37164, 220     - both off

POKE 37164, 222     - clock on

POKE 37164, 252  - data on

POKE 37164, 254     - both on

Reading the values is a little easier, just use 


If bit 0 is clear, then the CLK pin on the bus is active (low). If bit 1 is clear then the DAT pin on the bus is active (low).

I have been through this process in various forms, trying to talk people through diagnosing faults.

I looked at trying to automate this, and put together a BASIC program.

The idea was it would cycle through all combinations of outputs, and show the inputs. If all was working, the inputs would follow the outputs.

ATN is only an output, so the input side does nothing. I did want to get it to display SRQ as an input, but on the VIC20 it can only trigger an interrupt, and you have to tell it to look for a positive or a negative edge. In practice, it only needs to trigger on a falling edge, but for the purpose of displaying that value, it's not easy to read the actual state.

The BASIC version was very simple, and it worked, but was a bit slow to update, so it didn't always look to be in phase.

I decided to rewrite it in assembler, and also add a bit more information to the screen.

My plan was the cycling through combinations would pulse the outputs at a set frequency, so you could monitor them on a scope.

I had tried using a FOR NEXT loop to delay the BASIC program, but that was no where near accurate enough. When I rewrote it in assembler, I added an IRQ handler routine to count the jiffy pulses.

I went for 1Hz for CLK, with half of that for data and half again for ATN

I picked those up on the ferrite beads, but you can use any of the IC pins of the socket itself.

I was very pleased with how accurate the timing worked out.

If one of them is stuck, you will see it not toggling.

You can also see the output on the screen, with a much faster update thanks to being written in assembler.

When the output is red, the matching input should be red,, and likewise with green. If there is a problem, the colour will not change when it should.

Where can I find the IEC port tester?

One problem with something like this is you need the IEC port to be working to load the test program to see if the IEC port is working.....

But fear not, the IEC port tester is built into the Penultimate +2 cartridge, so you can run it directly from there.

See for more information.

So, what causes these problems?

In that case, it was a bad 7406. I knew that already as it was a chip I had removed from a C64 board because it had failed.

This is the MOS 7707, which is a MOS produced 7406 replacement, and for some reason, they seem to fail more than the standard 7406's.

A new 7406 was fitted to that board and the IEC bus started working again.

So why do they fail?

Well, both the 7406 and 6522/6526 chips have pins connected to the outside world on the rear connectors, and you can get static via those pins, or voltage differentials when things are plugged in when live.

Later in the life of the C64, Commodore started retro-fitting clamping diodes across those pins, to add protection. Presumably they had seen enough failures in the field to justify it.

They were later added properly to the C64C. One diode to ground, one to 5V, on each pin. These should stop any voltages outside of that range from reaching the pins of the chips.

Which was much neater when they were part of the design.

They also make a handy point to pick up the connections if you are fitting an internal SD2IEC.

See an old blog post for more info on that:

C64 Pokes 

The same can be done on the Commodore 64, these are the PEEKs and POKEs you need:

You can do some simple tests by poking the 6526 from BASIC.

The port used by IEC is at 0xDD00, or 56576 in decimal.

The outputs go via a 7406 inverter (which often fails, especially if it is MOS part 7707 rather than an actual 7406.

You can test some of the pins by writing to the 6526 register and measuring the output voltages on the IEC port, and also on the 7406.

The outputs are read back from the IEC socket, so you can write to clock and data and read back to see if the values are being read back correctly.

Do all of these tests with nothing connected to the IEC port.

Google your mainboard part number to get a schematic to check the appropriate places to measure these values.

Bits #0-#1: VIC bank.

Bit #2: RS232 TXD line, output bit.

Bit #3: Serial bus ATN OUT; 0 = High; 1 = Low.

Bit #4: Serial bus CLOCK OUT; 0 = High; 1 = Low.

Bit #5: Serial bus DATA OUT; 0 = High; 1 = Low.

Bit #6: Serial bus CLOCK IN; 0 = Low; 1 = High.

Bit #7: Serial bus DATA IN; 0 = Low; 1 = High.

Bits 0-3 are used by the VIC and serial TX, so just leave those set to 1.

Bit 4 is the output for the ATN line. If you poke a number where bit 4 is high, the ATN pin should go low.

POKE 56576,7+8    (0000 1111)

then poke a number with but 4 low and the output pin should go high again.

POKE 56576,7                (0000 0111)

bits 4 and 5 are output for clock and data, bits 6 and 7 are the inputs.

If you poke the various combinations of outputs, you should see the inverse read on the pins and on the inputs.

POKE 56576,7+7         (0000 0111)
199                                     (1100 0111)

POKE 56576,7+16      (0001 0111)
151                                     (1001 0111)

POKE 56576,7+32      (0010 0111)
103                                     (0110 0111)

POKE 56576,7+48      (0011 0111)
55                                        (0011 0111)

If any of those read wrong, you should be able to tell if it is the 6526 or 7406 at fault, and replace the appropriate part.


Penultimate +2 Cartridge

The Penultimate +2 Cartridge with the built in IEC port tester is available to pre-order from The Future Was 8 bit:

More info in a previous post:


You can support me via Patreon, and get access to advance previews of posts like this and behind the scenes updates. These are often in more detail than I can fit in here. This also includes access to my Patreon only Discord server for even more regular updates.