Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Winbond 25N01GVEIG memory chip wires to T4.0 Standard SPI

  1. #1

    Winbond 25N01GVEIG memory chip wires to T4.0 Standard SPI

    Hello all,
    I want to use a Winbond 25N01GVEIG in SPI mode to hold some data for me. I'm a bit ignorant of this chip and trying to decipher the datasheet. I've used other Winbond chips without too much drama but this one has me confused.

    I wired this up to my t4.0 like this;
    CS pin 10
    DI Pin 11
    DO Pin 12
    Clk Pin 13
    WP Pin 9
    HOld Pin 6
    VCC to 3.3v output pin of t4.0
    GND to GND

    Started to write simple commands to do the basics before turning it into my own library.

    The problem is I can't seem to correctly read or write to one or any of the 3 registers.
    No matter what I do it always returns Zeros for all 3 registers.
    If I send a write enable instruction it should change at least one of the 3 registers but doesn't.

    The code shown below is a simple test sketch I wrote to read and write registers.

    I have another sketch that proves I can write to the data buffer. I can read the data buffer but I can't Program execute to save the buffer to a page of memory.
    But I think the important part for me is to figure out why I can't read or write to the registers correctly.

    I read somewhere that " The /CS input must track the VCC supply level at power-up and power-down " " If needed, a pull-up resistor on the /CS pin can be used to accomplish this. "
    So I added a 6K resistor from 3.3v pin to pin 10 and it didn't change anything for me.

    Sorry for the Ruff code, just trying to make it work before cleaning it all up.
    Code:
    #include <SPI.h>
    
    void setup() {
    pinMode(10, OUTPUT); digitalWrite(10, HIGH);
      pinMode(9, OUTPUT); digitalWrite(9, LOW);// Write Protect
      pinMode(6, OUTPUT); digitalWrite(6, HIGH);// HOLD
    
    
    
      Serial.begin(115200);
      delay(2000);
    
    
    /////// START SPI  
      Serial.println("Start");
      digitalWrite(10, HIGH);
      SPI.begin();
      SPI.setBitOrder(MSBFIRST);
      SPI.setDataMode(SPI_MODE3);
    
    //// RESET WINBOND
      Serial.println("RESET ");
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0xFF);
      digitalWrite(10, HIGH); 
      SPI.endTransaction();    
      delay(1000);///. WAIT FOR RESET ??
    
    /// TEST SPI BY ASKING FOR ID
      SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x9F);
      SPI.transfer(0xAA);
      byte val = SPI.transfer(0);
      byte val1 = SPI.transfer(0);
      byte val2 = SPI.transfer(0);
      digitalWrite(10, HIGH);
      SPI.endTransaction();
      Serial.print("Manufacturer ID: ");
      Serial.print(val,HEX);
      Serial.print(" ");
      Serial.print(val1,HEX);
      Serial.print(" ");
      Serial.print(val2,HEX);
      Serial.println(" ");
    
    //// READ REGISTERS
      SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
        digitalWrite(10, LOW);
      SPI.transfer(0x0F);
      SPI.transfer(0x0A);
      val = SPI.transfer(0);
      digitalWrite(10, HIGH);
      //SPI.endTransaction(); 
      Serial.print("Register #1 ");Serial.println(val,HEX);
    
    //SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
        digitalWrite(10, LOW);
      SPI.transfer(0x0F);
      SPI.transfer(0x0B);
      val1 = SPI.transfer(0);
      digitalWrite(10, HIGH);
      //SPI.endTransaction(); 
      Serial.print("Register #2 ");Serial.println(val1,HEX);
      
      //SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
      digitalWrite(10, LOW);
      SPI.transfer(0x0F);
      SPI.transfer(0x0C);
      val2 = SPI.transfer(0); 
      digitalWrite(10, HIGH);
      SPI.endTransaction(); 
      Serial.print("Register #3 ");Serial.println(val2,HEX);
    
    
    
    
    /// ERASE BLOCK ZERO
     Serial.println("Erase");
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x6);//WRITE_ENABLE
      digitalWrite(10, HIGH); 
      SPI.endTransaction();
    delay(10);
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0xD8);// BLOCK ERASE
      SPI.transfer(0xAA);
      SPI.transfer(0x0);
      SPI.transfer(0x0);  
      digitalWrite(10, HIGH); 
      SPI.endTransaction();
      delay(100);
    
    
    /// SET Registers
     Serial.println("SET Registers");
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x6);//WRITE_ENABLE
      digitalWrite(10, HIGH); 
      SPI.endTransaction();
    
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x1);
      SPI.transfer(0xB);
      SPI.transfer(0x20);  
      digitalWrite(10, HIGH);
      SPI.endTransaction();
    
    delay(10);
    
    
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x6);//WRITE_ENABLE
      digitalWrite(10, HIGH); 
      SPI.endTransaction();
    delay(10);
       SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x1);
      SPI.transfer(0xA);
      SPI.transfer(0x20);  
      digitalWrite(10, HIGH);
      SPI.endTransaction();
    ///END SET Registers
    
    
    
    //// READ REGISTERS
      SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
        digitalWrite(10, LOW);
      SPI.transfer(0x0F);
      SPI.transfer(0x0A);
      val = SPI.transfer(0);
      digitalWrite(10, HIGH);
      //SPI.endTransaction(); 
      Serial.print("Register #1 ");Serial.println(val,HEX);
    
    //SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
        digitalWrite(10, LOW);
      SPI.transfer(0x0F);
      SPI.transfer(0x0B);
      val1 = SPI.transfer(0);
      digitalWrite(10, HIGH);
      //SPI.endTransaction(); 
      Serial.print("Register #2 ");Serial.println(val1,HEX);
      
      //SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
      digitalWrite(10, LOW);
      SPI.transfer(0x0F);
      SPI.transfer(0x0C);
      val2 = SPI.transfer(0); 
      digitalWrite(10, HIGH);
      SPI.endTransaction(); 
      Serial.print("Register #3 ");Serial.println(val2,HEX);
    
    
      
       
    
    /// TEST SPI BY ASKING FOR ID
      SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
      digitalWrite(10, LOW);
      SPI.transfer(0x9F);
      SPI.transfer(0xAA);
      val = SPI.transfer(0);
      val1 = SPI.transfer(0);
      val2 = SPI.transfer(0);
      digitalWrite(10, HIGH);
      SPI.endTransaction();
      Serial.print("Manufacturer ID: ");
      Serial.print(val,HEX);
      Serial.print(" ");
      Serial.print(val1,HEX);
      Serial.print(" ");
      Serial.print(val2,HEX);
      Serial.println(" ");
    
    
    
    }
    
    void loop() {
    
    
    }


    This results in the following from the Serial Monitor;
    Code:
    Start
    
    RESET 
    
    Manufacturer ID: EF AA 21 
    
    Register #1 0
    
    Register #2 0
    
    Register #3 0
    
    Erase
    
    SET Registers
    
    Register #1 0
    
    Register #2 0
    
    Register #3 0
    
    Manufacturer ID: EF AA 21
    This to me proves it is wired correctly and can talk back and forth on the SPI bus because the Manufacturer ID is correct to this chip.
    But why can't I read or write or change anthing in the registers.

  2. #2
    Senior Member
    Join Date
    Sep 2015
    Posts
    108
    I'm pretty sure you should be in SPI mode 0 the whole time rather than switching to mode 3.

  3. #3
    Quote Originally Posted by ecurtz View Post
    I'm pretty sure you should be in SPI mode 0 the whole time rather than switching to mode 3.
    You are correct. I've been trying everything I can think of to make this work. I just changed it all to SPI_MODE0 with no change.

  4. #4
    Senior Member
    Join Date
    Sep 2015
    Posts
    108
    It looks like some of your constants are wrong as well. The registers should be A0, B0, C0 rather than 0A, 0B, 0C

  5. #5
    Quote Originally Posted by ecurtz View Post
    It looks like some of your constants are wrong as well. The registers should be A0, B0, C0 rather than 0A, 0B, 0C
    Well, that seems to have worked! I need to do more testing but..... Thanks

    I was reading page 25 of the datasheet that says Addr = Axh I thought that meant 0x0A not 0xA0

  6. #6
    Quote Originally Posted by ecurtz View Post
    It looks like some of your constants are wrong as well. The registers should be A0, B0, C0 rather than 0A, 0B, 0C
    That absolutely worked! I needed to make a write to the Protection Register in order to allow a write to memory! Thank you! I took till now to understand Axh, Bxh, Cxh

  7. #7
    Senior Member
    Join Date
    Sep 2015
    Posts
    108
    Glad you got it working. I hope that as soon as the upcoming "generic File" stuff from Paul is finalized there will be a push for a more unified library for this stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •