1

I am trying to interface a 3.5" floppy drive (read and write data onto floppy disc). Since I need to write just few bit long number on it (16 is more than enough) I am thinking I could write it track-wise (each track is one bit), which gives me teoretically 80 bit long number, so I could write 4 times 16 bit long number for some redundancy.

I found this code, which solves reading data out. For writing I found this page which says, that writing should be similar easy process.

I attached code I am running here. Reading seems to work, but writing not. The interesting part of code is:

void writeData(byte data){
  Serial.println("Writing");
  digitalWrite(writeEnablePin, LOW); //starting spining a motor
  digitalWrite(motorEnableBPin, LOW); //enabling motorEnable
  stepAllTheWayOut(); //moving head to the edge of drive
  for(unsigned i = 0; i<10; i++){ //repeating 10 times
    for(unsigned index = 0; index<=8; index++){ //repeating 8 times (there are 80 tracks)
      digitalWrite(writeDataPin,bitRead(data,index)); //setting data pin
      Serial.print(bitRead(data,index)); //printing out what is being written
      delay(500); //spinning for a while to write all over the track
      digitalWrite(writeEnablePin, HIGH); //stepping not working when writeEnablePin is LOW
      stepIn();
      digitalWrite(writeEnablePin, LOW);
    }
    Serial.println("");
  }
  digitalWrite(motorEnableBPin, HIGH);
  digitalWrite(writeEnablePin, HIGH);
}

The output is:

Setup done.
Writing
010101010
010101010
010101010
010101010
010101010
010101010
010101010
010101010
010101010
010101010
Reading
111001000
101010001
110111001
001000101
001011001
111111101
110101101
111110011
111111001
101111110

The output is not what should be written. (the bits are changed every time i run the code)

Any idea what am I doing wrong when writing?

  • Okay, I have little knowledge but I will try my best. 1)Have you tried erasing the disk completely you might be trying to read already written data. 2) Have you checked the timings of the byte sequence. That's all I can think of, sorry if it's not helpful. – Alex Jan 15 '19 at 21:15
2
for(unsigned index = 0; index<=8; index++)

I think that need to be

for(unsigned index = 0; index<8; index++)

Otherwise you are trying to read the 9th bit in a byte.

| improve this answer | |
  • Nice. That is faulty indeed. Doesn't solve reading-writing problem at all though... – slune Feb 15 '17 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.