Now Reading
Bit Banging a 3.5″ Floppy Drive

Bit Banging a 3.5″ Floppy Drive

2023-12-19 12:09:27

Welcome to the floppy cafe! These pages are the misplaced and sacred
texts you’ve got been in search of in case you occur to be writing a driver for
a 3.5″ floppy. To study these mysteries, I bit-banged a floppy drive
utilizing a
and managed to jot down a full driver for it. My undertaking code is hosted
here on github
in case you’d wish to study extra. Proceed studying for an especially
detailed overview of the undertaking and all my findings on this journey.
Though the knowledge is basically widespread for any floppy drive, is devoted particularly to three.5″ media.

Desk of Contents

How do Floppy Disks

has a superb overview and a few good photos. Essentially, your floppy
homes a magnetized disk that spins at about 300rpm. For 3.5″ media,
that disk incorporates 80 tracks. Every monitor has 18 sectors. Every sector has
512 bytes of user-space information (and a few extra bytes used for metadata).
Most “trendy” floppies are double-sided, so you possibly can multiply all that by
2 so as to discover the whole quantity of usable house per disk.
1,474,560 bytes in all.

Enjoyable truth! floppy disks really comprise much more floor space
than 1.44mb. By my calculation, you may get nearer to 1.70mb however a number of
that additional house is earmarked for
synchronization barriers and
sector / monitor metadata.

Wiring Information

This is the cool factor about floppy drives: they haven’t any communication
protocol! It is only a bunch of gpio pins. For many of them, pulling the
pin HIGH means it’s within the “disabled” or “off” state.
Pulling a pin LOW will activate it. You possibly can learn in regards to the
very detailed specs for the
floppy drive. The highest row of pins are the features, the underside row of
pins are all LOGIC GROUND. Logic. Did you get that? LOGIC! Not
motor floor. I had them wired up improper for weeks and puzzled why
nothing labored. And, sure, there’s like 1,000,000 floor pins however you
solely want 1 to get it working.

An essential notice! the logic-level pins are rated for 5v,
nonetheless, you should utilize 3v3 in a pinch! Why is that? All these information pins
are open drain and ought to be hooked as much as a
pull-up resistor. Meaning the one manner these floppy drives
communciate again is by sinking the voltage. So 3v3, 5v, it does not
matter. The floppy drive will fortunately pull it down.

Protip! A few of the backside row of pins are
not linked internally! So in case you are plugging in simply 1 floor
wire and it isn’t working, chances are high the bottom pin you chose is
disconnected. Strive one other one.

A page from a guide showing what each pin on the back of a floppy drive does.

You will discover the facility part solely wants two wires. 5v+ and one other
floor. On your sanity, I counsel utilizing a separate energy bus than
no matter your microcontroller is on.

Please don’t join the 5v+ to an arduino or a GPIO! It will probably draw
upwards of 1A throughout actually feisty operations and it’ll
fry your microcontroller!

Sending Instructions

There are a selection of instructions and proceedures you have to to
implement so as to assume management of the floppy drive. Basically,
instructions are issued by pulling a given pin LOW.

A phrase of warning: I’ve learn on-line the Arduino inner pull-ups
aren’t nice. They’re going to work for many of those pins
besides the info line. You could wish to add a 4.5k pull-up to the
DATA line as an alternative of counting on the built-in pull-ups.

Alright! Let’s discover every perform you will have entry to.


The floppy drive does not actually know the place you’re at any given
time. You possibly can suss this out with varied mechanisms, and a type of
mechanisms is the INDEX pin. The index pin is the primary usable
pin on the highest row (pin 8). When this pin is LOW, the disk
has made one full revolution and is at present in the beginning of the
information stream.

In my driver, I’d typically search for HIGH to
LOW transitions and use this to increment an error counter.
If I am unable to full some process after 10 revolutions or so, I contemplate the
drive in a nasty state.

Drive Choose

There are a number of completely different drive choose pins (typically for drive 0, 1, and
2) however the principle one we’re fascinated by is
PIN 12 often known as DRIVE SELECT 1. The opposite
ones are reserved for controlling a number of floppy drives directly. This
perform is used to allow the floppy drive. Pulling it
will present you entry to all the opposite I/O features besides
MOTOR ON. That one is agnostic of drive choose.

Motor On

Because the identify suggests, this pin is devoted to controlling the motor. To
allow the motor, pull this pin
LOW after which wait 500ms. It is good apply to watch the
INDEX line as nicely for a HIGH to
LOW transition, indicating that the spindle has made a
full revolution.

Course Choose

This pin controls the route that the monitor stepper motor pin
will transfer in, whenever you pulse the STEP pin. Pulling this pin
LOW will orient the monitor stepper motor to maneuver in direction of the
middle of the magnetic disk (growing the monitor quantity). Pulling this
pin HIGH will orient the monitor stepper to maneuver in direction of the
exterior of the magnetic disk (reducing the monitor quantity).


There are 80 tracks in your common 3.5″ floppy drive. You possibly can choose a
given monitor by pulsing the STEP pin and mixing it with
the route choose pin.

Pulsing this pin will cost and actuate a stepper motor. As such, there
are some particular timing necessities. I like to tug it
LOW for 3ms after which pull it
HIGH for a further 3ms and go away it within the
excessive state till the subsequent pulse. The documentation states it may be low
for as brief as 0.15us however that did not work for me
persistently throughout different drives.

Write Information

If you wish to know much more about this pin, head on over to the
MFM ENCODING web page for a primer on easy methods to use it.
From a technical perspective, pulsing this pin will reverse the flux
route on the magnetized disk. Basically, you’ll maintain the pin
LOW for about 0.15us to 1.1us after which deliver
it again to a HIGH state. How lengthy it stays within the excessive
state determines the encoded worth in line with the MFM guidelines.

Write Gate

Pusling the write information pin will do nothing if the gate is closed. To
start writing information, it’s essential to pull this pin LOW and maintain it
low throughout your write operation.

You can’t learn and write on the identical time.

Enjoyable truth! Whereas I used to be creating my driver, I ruined many total
tracks by leaving this open for too lengthy. For those who aren’t cautious, it’s going to
wreck the sector metadata and synchronization obstacles and completely
destroy your floppy disk. Reformatting the disk ought to restore steadiness
to the power, so this would possibly not be a complete loss.

Observe 00

The floppy drive controls this pin, and when it will get pulled
LOW which means the learn/write head is positioned on
the primary monitor (monitor 0).

Write Shield

When a write-protected media is insertted, this pin might be pulled
LOW by the floppy drive and the info on the disk is
shielded from mis-erasing. When the pin is HIGH the
floppy drive might be written.

See Also

This solely appears to work if the drive choose pin has been pulled

Learn Information

A HIGH to LOW transition on this line
signifies the flux route has modified on the underlying magnetic
disk. When you encouter this transition, rely all of the clock cyles
between the vanguard of the LOW sign to the
trailing edge of the HIGH sign.

Aspect Choose

These 3.5″ floppy disks have 2 sides. Pulling this pin
HIGH selects the decrease facet (facet 0). Pulling this pin
LOW selects the higher facet (facet 1).

Prepared/Disk Change

I by no means obtained this to work, however the spec says it is going to both inform you if
the drive is in a prepared state or not. When the floppy drive pulls this
pin LOW, the drive is prepared for operation. In any other case, the
pin might be left in a HIGH state.


Between every monitor is a synchronization barrier. This barrier is
surprisingly simple to search out as a result of it’s simply 12 0x0 bytes
adopted by 3 0xA1 bytes. By way of pulses, it quantities to
to 96 brief pulses adopted by the sequence of pulses MLMLMSLMLMSLMLM.
You’ll have bother studying all 96 pulses due to timing. A standard
apply is to hunt for a minimum of 80 pulses as an alternative.
This will provide you with a bit extra resilience.

Sector Metadata

Every sector is comprised of some metadata to explain it. The metadata
is formatted like so:

  • 12 bytes of 0x0
  • 3 bytes of 0xA1
  • One byte of 0xFE
  • One byte to point the monitor quantity
  • One byte to point the facet (or head)
  • One byte to point thes sector quantity
  • One byte to point the sector dimension
  • 2 bytes of CRC (cyclic redundancy code) computed from the sector
  • 22 bytes of 0x4E
  • 12 bytes of 0x0
  • 3 bytes of 0xA1
  • 1 byte of both 0xFA or 0xFB
  • 512 bytes of consumer information
  • 2 bytes of CRC computed from the consumer information
  • Unspecified quantity of 0x4E bytes filling within the remaining
    house between sectors

Upon cautious inspection, we will see there are literally two
synchronization obstacles. One to search out the sector metadata, and one other
to search out the userspace information.
The one distinction is the byte that follows. For sectors, the quick
byte after the barrier is 0xFE. For userspace information, it is both
0xFA or 0xFB.
That is how we will decide which form of barrier we have run into.

Observe Metadata

Every monitor additionally has its personal set of metadata which is formatted like so:

  • 80 bytes of 0x4E
  • 12 bytes of 0x00
  • 3 bytes of 0xC3
  • One byte of 0xFC
  • 50 bytes of 0x4E

Additional Studying

Here’s a complete listing of extra sources:

Subsequent, let’s take a look at MFM ENCODING to study extra
about how information is saved.

Source Link

What's Your Reaction?
In Love
Not Sure
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top