NAND Flash Reader

Hello,

i am trying to create a Nand Flash Reader to create raw backups. I have connected a tsop48 socket with a flash to my arduino pro mini 3.3V 8MHz. The flash is from an old 32MB usb stick. First i am trying to read the manufacturer and the device id but i have no success yet.
Anybody with ideas or a similar project who can help me?

// Pin Setup
int datapin[8];
  
int we = 5;
int ale = 4;
int cle = 3;
int re = 14;
int ce = 15;
int rb = 16;

// Vars Setup
int inByte = 0;
unsigned char buffer[528];
 
void setup() 
{  
  for(int i=0;i++;i<=7)
  {
    datapin[i] = 6 + i;
  }
  
  pinMode(we, OUTPUT);
  pinMode(ale, OUTPUT);
  pinMode(cle, OUTPUT);
  pinMode(re, OUTPUT);
  pinMode(ce, OUTPUT);
  
  // Serial Setup
  Serial.begin(9600); 
  Serial.println("NAND Flash Reader v1.0"); 
}

void ioop()
{
  for(int i=0;i++;i<=7)
  {
    pinMode(datapin[i], OUTPUT);
    digitalWrite(datapin[i], LOW);
  }
}

void ioip()
{
  for(int i=0;i++;i<=7)
  {
    pinMode(datapin[i], INPUT);
  }
}

void ASSERT_WE() {digitalWrite(we, HIGH);}
void DEASSERT_WE() {digitalWrite(we, LOW);}

void ASSERT_ALE() {digitalWrite(ale, HIGH);}
void DEASSERT_ALE() {digitalWrite(ale, LOW);}

void ASSERT_CLE() {digitalWrite(cle, HIGH);}
void DEASSERT_CLE() {digitalWrite(cle, LOW);}

void ASSERT_RE() {digitalWrite(re, HIGH);}
void DEASSERT_RE() {digitalWrite(re, LOW);}

void ASSERT_CE() {digitalWrite(ce, HIGH);}
void DEASSERT_CE() {digitalWrite(ce, LOW);}

void SendCommand(byte cmdByte)
{
  ASSERT_CLE();
  WriteByte(cmdByte);
  DEASSERT_CLE(); 
}

void SendAddress(byte addByte)
{
  ASSERT_ALE();
  WriteByte(addByte);
  DEASSERT_ALE();
}

void WriteByte(byte outByte)
{
  byte mask = 1;
  int i = 7;
  
  for (mask = 00000001; mask>0; mask <<= 1) {
    if (outByte & mask) {
      digitalWrite(datapin[i], HIGH);
    }
    else {
      digitalWrite(datapin[i], LOW);
    }
    i--;
  }
  ASSERT_WE();
  DEASSERT_WE();
}

void ReadByte(int length)
{
  int bytecount = 0;
  int pin = 7;
  unsigned char tempByte;
  
  while(bytecount < length) {
    ASSERT_RE();
    delay(10);
    // Debug
    for (int i = 0; i<8;i++) {
    if (digitalRead(datapin[i]) == HIGH) {
      Serial.print("1");
    }
    else {
      Serial.print("0");  
    }
    }
    
    pin = 7;
    buffer[bytecount] = tempByte;
    bytecount++;
    DEASSERT_RE();
  }
}

void loop()
{
  if (Serial.available() > 0) {
    char inByte = Serial.read();
    Serial.println("send: ");
    Serial.print(inByte, BYTE);
    if (inByte == 'R') {
      Serial.println("Reading...");
      readDeviceID();
      Serial.println("Done!");
    }
  }
}

void readDeviceID()
{
   ioop();
   delay(5);
   ASSERT_CE();
   SendCommand(0x90); // 90h = Read ID
   SendAddress(0x00);
   ioip();
   //delay(50);
   ReadByte(2); // 2 Bytes 1 = Manufacturer ID, 2= Device ID
   DEASSERT_CE();
   
   Serial.print("Manufacturer ID: ");
   Serial.println(buffer[0], HEX);
   Serial.print("Device ID: ");
   Serial.println(buffer[1], HEX);
}

best regards
Xaptor