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

Thread: DIY EEPROM programmer with teensy 3.6

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    3

    DIY EEPROM programmer with teensy 3.6

    I am trying to program an EEPROM chip with Teensy 3.6. The EEPROM is: Microchip SST39LF040-55-4C-NHE.

    Here is the code which also shows which pins on the teensy are connected to what on the eeprom (ardunio IDE on windows).

    So A0-A7 is using pins 0-7.
    A7 to A17 uses pins 14-23
    And A18 uses pin 39

    D0-D7 use pins 0-7.

    WE is pin 38.
    OE is pin 37.
    CE is tied to ground (active low, so its always enabled).

    Code:
    //Written poorly by mikemint64
    //visit at mint64.home.blog
    
    #define TEENSY
    
    #ifdef TEENSY
      #define WE 38
      #define OE 37
      
      const long AddrPins[] =
      {
        // A0 - A7
        24,  25,  26,  27,  28,  29,  30,  31,
      
        // A8-A17
        14,  15,  16,  17,  18,  19,  20,  21,
        22,  23,
        // A18
        39
      };
      
      const long DataPins[] =
      {
        0,  1,  2,  3,  4,  5,  6,  7
      };
    
    
    #else
      #define WE 2
      #define OE 3
      
      const long AddrPins[] =
      {
        // A0 - A7
        22,  23,  24,  25,  26,  27,  28,  29,
      
        // A8-A17
        30,  31,  32,  33,  34,  35,  36,  37,
        38,  39,
        // A18
        40
      };
      
      const long DataPins[] =
      {
        44,  45,  46,  47,  48,  49,  50,  51
      };
    #endif
    
    void setCtrlPins();                                   //Setup control signals
    void setAddrPinsOut();                                //Setup address signals
    void setDigitalOut();                                 //Set D0-D7 as outputs
    void setDigitalIn();                                  //Set D0-D7 as inputs
    void setAddress(unsigned long addr);                  //Set Address across A0-A18
    void setByte(byte out);                               //Set data across D0-D7
    byte readByte();                                      //Read byte across D0-D7
    void writeByte(byte data, unsigned long address);     //Write a byte of data at a specific address
    void programData(byte data, unsigned long address);   //Executes the program command sequence
    byte readData(unsigned long address);                 //Read data as specific address
    void eraseChip();                                     //Executes the erase chip command sequece
    void readSerialCommand(byte in);                      //Decodes incomming serial commands 
    
    
    void setup() 
    {
      setDigitalIn();
      setCtrlPins();
      setAddrPinsOut();
    
      Serial.begin(9600);
      delay(2);
      Serial.println("Started Serial COM");
    
    
    }
    
    void loop()
    {
      if (Serial.available())
      {
        readSerialCommand( Serial.read() );
      }
    }
    
    const static int kChunkSize = 1024;
    
    void readSerialCommand(byte in)
    {
      switch(in)
      {
        case 'I':
        getIds();
        break;
        
        default : Serial.print("Invalid Command"); break;
      }
    }
    
    void eraseChip()
    {
      setDigitalOut();
    
      writeByte(0xAA, 0x5555);
      writeByte(0x55, 0x2AAA);
      writeByte(0x80, 0x5555);
      writeByte(0xAA, 0x5555);
      writeByte(0x55, 0x2AAA);
      writeByte(0x10, 0x5555);
    
      delay(100);
      setDigitalIn();
    }
    
    byte readData(unsigned long address)
    {
      byte temp_read;
      setDigitalIn();
      
      digitalWrite(WE, HIGH);
      digitalWrite(OE, HIGH);
      
      setAddress(address);
      
      digitalWrite(OE, LOW);
      delayMicroseconds(1);
    
      temp_read = readByte();
      
      digitalWrite(OE, HIGH);
    
      delayMicroseconds(60);
     
      return temp_read;
    }
    
    void writeByte(byte data, unsigned long address)
    {
      digitalWrite(OE, HIGH);
      digitalWrite(WE,HIGH);
      
      setAddress(address);
      setByte(data);
      delayMicroseconds(30);
      
      digitalWrite(WE, LOW); // latch address
      delayMicroseconds(40); //  min 40 nsec
      digitalWrite(WE, HIGH);// latch data
      delayMicroseconds(30); //  min 40 nsec
    }
    
    void programData(byte data, unsigned long address)
    {
      setDigitalOut();
      
      writeByte(0xAA, 0x5555);
      writeByte(0x55, 0x2AAA);
      writeByte(0xA0, 0x5555);
      writeByte(data, address);
      
      delayMicroseconds(1);
    }
    
    void getIds()
    {
      setDigitalOut();
      
      writeByte(0xAA, 0x5555);
      writeByte(0x55, 0x2AAA);
      writeByte(0x90, 0x5555);
    
      delayMicroseconds(150);
    
      byte manId = readData(0);
      byte devId = readData(1);
    
      Serial.println(manId, HEX);
      Serial.println(devId, HEX);
         
    }
    
    
    byte readByte()
    {
      byte temp_in = 0;
      for(int i = 0; i < 8; i++)
      {
        if (digitalRead( DataPins[i]))
        { 
          bitSet(temp_in, i);
        }
      }
      return temp_in;
    }
    
    void setByte(byte out)
    {
      for(int i = 0; i < 8; i++)
        digitalWrite( DataPins[i], bitRead(out, i) );
    }
    
    void setAddress(unsigned long addr)
    {
      for(int i = 0; i < 19; i++)
        digitalWrite( AddrPins[i] , bitRead(addr, i) );
    }
    
    void setAddrPinsOut()
    {
      for(auto i : AddrPins)
      {
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
      }
    }
    
    void setDigitalOut()
    {
      for(auto i : DataPins)
        pinMode(i, OUTPUT);
    }
    
    void setDigitalIn()
    {
      for(auto i : DataPins)
        pinMode(i, INPUT);
    }
    
    void setCtrlPins()
    {
      pinMode(WE, OUTPUT);
      pinMode(OE, OUTPUT);
    
      digitalWrite(WE, HIGH);
      digitalWrite(OE, HIGH);
    }
    I have used this same code with an arduino mega (hence the #define for switching the pin numbers). When I run this on a mega with a Microchip SST39SF040-70-4C-PHE which is effectively the 5v version of the above chip it works and returns:

    Name:  chipid.png
Views: 44
Size:  1.7 KB

    Also a logic analyser trace: (0-7 = D0-D8, 8=RD and 9=RW).

    Click image for larger version. 

Name:	logic_trace.jpg 
Views:	3 
Size:	65.6 KB 
ID:	19495

    I've got a couple of other spare EEPROM chips and they all result in 0xFF being returned for the product and manufacture id. I would appreciate any clues on what I could possibly do to try to debug this. Hopefully one of the pins I've used on the teensy is perhaps reserved or something?

  2. #2
    Junior Member
    Join Date
    Mar 2020
    Location
    New York
    Posts
    4
    Did you get a way out? I'd like to learn

  3. #3
    Junior Member
    Join Date
    Mar 2020
    Posts
    3
    Quote Originally Posted by Sydneycl View Post
    Did you get a way out? I'd like to learn
    Still no clue what is going on at the moment, since the 5v rom works I'm thinking I'll just use level shifters to talk to my other 3v chips and stick with arduino to program the eeprom.

Posting Permissions

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