Nand Flash auslesen Atmega 328[Arduino]

OP #1574042
Lesenswert?

Hallo,

ich wollte gestern mal versuchen mit dem Arduino (Atmega 328) einen Nand 
Flash auszulesen. Leider habe ich kein Datenblatt zum Flash Chip 
allerdings scheinen die Standard Tsop48 aus den USB Sticks ja kompatibel 
zu sein oder sehe ich das falsch? Also habe ich einfach auf gut Glück 
auf ein Samsung Datenblatt zurückgegriffen und erstmal versucht die 
Manufacturer und Device ID auszulesen erhalte aber beidesmal 0xFF 
zurück. Würde mich freuen wenn jemand mal einen Blick über meinen Code 
werfen kann und evtl. den Fehler findet.


// 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);

  digitalWrite(we, LOW);
  digitalWrite(ale, LOW);
  digitalWrite(cle, LOW);
  digitalWrite(re, LOW);
  digitalWrite(ce, LOW);

  ioip();

  // 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;
  Serial.println();
  for (mask = 10000000; mask>0; mask >>= 1) {
    if (outByte & mask) {
      digitalWrite(datapin[i], HIGH);
      Serial.print("1");
    }
    else {
      digitalWrite(datapin[i], LOW);
      Serial.print("0");
    }
    i--;
  }
  Serial.println();
  ASSERT_WE();
  DEASSERT_WE();
}

void ReadByte(int length)
{
  int bytecount = 0;
  int pin = 7;
  unsigned char tempByte;

  while(bytecount < length) {
    ASSERT_RE();
    /*for (char bit = 0; bit < 8; bit++) {
      tempByte = tempByte << 1;
      tempByte = tempByte & 0xfe;
      tempByte = tempByte | (digitalRead(datapin[pin]));
      pin--;
    } */
    // 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++;
    delay(10);
    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();
   delay(1);
   SendCommand(0x90);
   SendAddress(0x00);
   ioip();
   delay(5);
   ReadByte(2); // 2 Bytes einlesen 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);
}
OP #1574159
Lesenswert?

Hmm leider ist immernoch ein Wurm drin.

// 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<8;i++)
  {
    datapin[i] = 6 + i;
  }

  pinMode(we, OUTPUT);
  pinMode(ale, OUTPUT);
  pinMode(cle, OUTPUT);
  pinMode(re, OUTPUT);
  pinMode(ce, OUTPUT);

  digitalWrite(we, LOW);
  digitalWrite(ale, LOW);
  digitalWrite(cle, LOW);
  digitalWrite(re, LOW);
  digitalWrite(ce, LOW);

  ioip();

  // Serial Setup
  Serial.begin(9600);
  Serial.println("NAND Flash Reader v1.0");
}

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

void ioip()
{
  for(int i=0;i<8;i++)
  {
    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 & 0x000000FF);
  DEASSERT_ALE();
}

void WriteByte(byte outByte)
{
  byte mask = 1;
  int i = 7;
  Serial.println();
  for (mask = 10000000; mask>0; mask >>= 1) {
    if (outByte & mask) {
      digitalWrite(datapin[i], HIGH);
      Serial.print("1");
    }
    else {
      digitalWrite(datapin[i], LOW);
      Serial.print("0");
    }
    i--;
  }
  Serial.println();
  ASSERT_WE();
  delay(5);
  DEASSERT_WE();
}

void ReadByte(int length)
{
  int bytecount = 0;
  int pin = 7;
  unsigned char tempByte;

  while(bytecount < length) {
    ASSERT_RE();
    /*for (char bit = 0; bit < 8; bit++) {
      tempByte = tempByte << 1;
      tempByte = tempByte & 0xfe;
      tempByte = tempByte | (digitalRead(datapin[pin]));
      pin--;
    } */
    // 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++;
    delay(10);
    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();
   delay(1);
   SendCommand(0x90);
   delay(5);
   SendAddress(0x00);
   ioip();
   delay(10);
   ReadByte(2); // 2 Bytes einlesen 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);
}
Gast #1574169
Lesenswert?

Reinhard Joswig schrieb:
> ich wollte gestern mal versuchen mit dem Arduino (Atmega 328) einen Nand
> Flash auszulesen. Leider habe ich kein Datenblatt zum Flash Chip
> allerdings scheinen die Standard Tsop48 aus den USB Sticks ja kompatibel
> zu sein oder sehe ich das falsch? Also habe ich einfach auf gut Glück
> auf ein Samsung Datenblatt zurückgegriffen und erstmal versucht die
> Manufacturer und Device ID auszulesen erhalte aber beidesmal 0xFF
> zurück. Würde mich freuen wenn jemand mal einen Blick über meinen Code
> werfen kann und evtl. den Fehler findet.

Reinhard Joswig schrieb:
> Leider habe ich kein Datenblatt zum Flash Chip allerdings scheinen die
> Standard Tsop48 aus den USB Sticks ja kompatibel zu sein oder sehe ich
> das falsch?

Keine Ahnung... Was hältst du davon, uns mal den Typ des ICs zu nennen? 
Vielleicht finden wir ja ein Datenblatt...
Gast #1574170
Lesenswert?

Den Scheiß unten benennst du erstmal um

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

void CE_HIGH() {digitalWrite(ce, HIGH);}
void CE_LOW() {digitalWrite(ce, LOW);}

Dann kann ein normaler Mensch auch was damit anfangen.
Nach meinen Erfahrungen mit Flash sind die meisten Signale
LOW aktiv. Das wären z.B. ce, re, we.
Persönliche Seite #1574325
Lesenswert?

Reinhard Joswig schrieb:
> Also folgendes steht drauf:
>
> A8M0820C
> USLCH0856M
> und etwas anders aufgedruckt M7SF1393Q4 vermute ein Produktionscode.
> Müsste ein 32MB Stick gewesen sein.

nein, bezeichnung sagt mir nix, ausser das 0856 schon passend sind zum 
8bit x 256M.

Atmel hat in dem NAND driver example auch init und reset vor dem read id

http://www.atmel.com/dyn/resources/prod_documents/EVK525-series6-ms_nf_df_sd-2_0_3-doc.zip
Gast #1725517
Lesenswert?

Reinhard Joswig escribió en el post # 1574208:
> Reinhard Joswig

Reinhard Joswig Hola!

Tengo El Mismo y me gustaria leer El chip de Contenido, ¿puedo "" Como 
Lograr la ESO?


¿Qué Tipo de micro Tengo? ¿Por Qué No Puedo leer ¿Con Ventanas o Linux?

Por adelantado, gracias?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren