Microchip 93xx6B SPI EEPROM instruction syntax

Hi all,

I currently am trying to work with the following EEPROM: http://www.microchip.com/wwwproducts/Devices.aspx?product=93C66B

Spec. sheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21795E.pdf

Attached is the code I currently have. I may be completely off here. I am struggling mostly with the syntax or the method to send instructions to the chip. Write now I have (6) wires connected (CS) (CLK) (SI) (SO) (VCC) (VSS). If anyone could point me in the right direction, whether a different library or method other than SPI.h that would be great.

//Experimenting with external EEPROM chip, Microchip 93C66B

#include <SPI.h>

const int slaveSelectPin = 9;

word outputValue = 0;
byte data = 0;

void setup()
{
  Serial.begin(9600);
  
  pinMode(slaveSelectPin, OUTPUT);
  digitalWrite(slaveSelectPin, LOW);
  
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  SPI.setDataMode(SPI_MODE0);
  SPI.begin();
}

void loop(){
  //ERASE/WRITE ENABLE
  // take the SS pin HIGH to select the chip:
  digitalWrite(slaveSelectPin, HIGH);
  //  send in the address and value via SPI:
  SPI.transfer(0b10011);
  // take the SS pin LOW to de-select the chip:
  digitalWrite(slaveSelectPin, LOW);
    
  //WRITE ALL
  // take the SS pin HIGH to select the chip:
  digitalWrite(slaveSelectPin, HIGH);
  //  send in the address and value via SPI:
  SPI.transfer(0b10001);
  for (int i = 0; i < 16; i++){
    SPI.transfer(0x06);
  }
  // take the SS pin LOW to de-select the chip:
  digitalWrite(slaveSelectPin, LOW);
  
  //READ
  // take the SS pin HIGH to select the chip:
  digitalWrite(slaveSelectPin, HIGH);
  //  send in the address and value via SPI:
  SPI.transfer(0b110);
  data = SPI.transfer(0x00);
  // take the SS pin LOW to de-select the chip:
  digitalWrite(slaveSelectPin, LOW);
  
  Serial.print(data);
  
  delay(200);
}

Looking at the data sheet, I see that the device requires 11 or 27 clock pulses for the various operations. I have not looked at the SPI code you refer to but the typical SPI code uses 8 or 16-bit values for each exchange. Therefore you may need to bit-bang the SPI interface for this device or use some other peripheral that gives you the flexibility to select (slightly) non-standard bit lengths for the values. I would also suggest that you look carefully at the timing requirements for operations such as the erase (where you need to give it time to do its work - between 2 and 6mSec) and write (similar time frames). Also when you write to the memory, you need to perform a "write enable" first. Susan

Thank you. I think the bit banging is the correct method for this chip. I was unsure of the timing needs, good to know that as well.

Something I still don't understand in the spec sheet is what exactly I should be sending to the chip.

For example. Erase-Write Enable operation, has a startbit of 1, OP code of 00 and under Address has 11XXXXXX. I don't know what I am supposed to be sending.

For other operations when the Address is listed as A7 A6 A5 A4 A3 A2 A1 A0, what does that mean for my send?

New to this and really wanting to understand. Thanks

The exact details are given in Section 3.2 (in conjunction with 3.1 and the timing diagrams etc.) but basically the sequence is:

  • take the CS line from low to high: this enable the chip and starts it ‘listening’ to the clock and data in lines (and readies the data out line)
  • set the pin connected to the EEPROM’s DI pin high - this is the “SB” or Start Bit mentioned in Table 1-3
  • set the pin connected to the EEPROM’s SCK pin high - this is the active edge of the clock
  • if you are expecting something back from the EEPROM, this is the time to read the pin connected to its DO pin - remember the value and shift it in to the right (lower bit) end of the received value
  • at some stage you can drop the clock line, taking into account the minimum pulse with (there is no maximum pulse with)
  • repeat the above 2 steps for the op-code that is appropriate (with the obvious setting of the data to the correct value - in your example these will both be “0”)
  • repeat the above steps again for the address (see below)
  • when everything has been sent, take the CS line low

For the ‘Erase - Write Enable’ instruction that you mention, only the first 2 bits are important and must be “1” as specified. The "X"s mean that the chip does not care what those values are and you can send either a “1” or a “0” as you see fit.
When you are sending an address or a data value, the data sheet is telling you that you need to send the most significant bit first. One way (and there are many others) is to AND the value you want to send (address or data) with 0x80 (assuming an 8 bit address - 0x8000 for a 16-bit value) and see if the result is zero or non-zero: if it is zero then the top bit is zero and if it is non -zero then the top bit is “1” and you and set the line accordingly. You can then shift the value left by one bit ( something like “x <<= 1;” can be used) and repeat for the next significant bit.
When you are reading a value back from the EEPROM, then you will also receive the data MSB first as well. That is why I suggested that you set the right-most (least significant bit) of a value with the “1” or “0” that you see in the pin connected to the EEPROM’s DO pin because you can then also shift that value left by one bit and slowly build up the correct value.
Remember that you need to send as many clock pulses as are specified in the Table 1-3 (11 or 27) and you will need to start sending and/or recording the address an data values on the appropriate clock pulses. The EEPROM can wait a long time between successive clock pulses but you must provide the required number of clock pulses to complete the instruction. (You can drop the CS line any time you like but that will cancel the instruction if you have not sent the required number of clock pulses).
Hope this is clear…???
Susan

Incredibly clear. I think I am better understanding. Reading that spec. sheet was definitely key, hopefully things like that become more apparent to me as I progress.

I will try and spend some time testing out what you just explained.

THANKS!

Got it to work flawlessly today after only maybe an hour’s effort. THANKS AGAIN!