Problems with parallel sram

If I run a blank sketch it stays at 4.93v (with all the components in the board).

With the ram_driver sketch:
No ic's: 4.93v
I add 1 shift register: 4.80v
I add another shift register: 4.55v
I add the ram chip: 4.05v (even lower than before)

Just to clarify: I've connected the top of the bus to the meter (vcc to incoming wire, com to the outgoing wire to the rest of the board). Is that the right way to measure?

Did you look at the code I think is wrong?

Here's the updated code:

	//Pin connected to ST_CP of 74HC595
	int latchPin = 8;
	//Pin connected to SH_CP of 74HC595
	int clockPin = 12;
	////Pin connected to DS of 74HC595
	int dataPin = 11;
	int bytePins[8] = {2,3,4,5,6,7,9,10};
	int CE = A2;
	int OE = A1;
	int WE = A0;
	
	#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))

	/*	mode: INPUT or OUTPUT
		OUTPUT: for writing out to memory
		INPUT: for reading from memory
	*/
	void setBytePins(int mode){
		for(int i=0 ; i < 8 ; i++){
			pinMode(bytePins[i], mode);
		}
	}
	
	void readBytes(unsigned char * buffer, unsigned short addr, int len){
		unsigned char b;
		setBytePins(INPUT);
		digitalWrite(CE, LOW);
		digitalWrite(OE, LOW);
		for( int i=0 ; i < len ; i++){
			b = readByte((int)addr+i);
			buffer[i] = b;
		}
		digitalWrite(OE, HIGH);    // Add this
		digitalWrite(CE, LOW);     // Add this
	}
	
	unsigned char readByte(unsigned short addr){
		setAddr(addr);
		return getByte();
	}
	
	unsigned char getByte(){
		unsigned char b=0;

		for( int i=0 ; i < 8 ; i++ ){
			b |= digitalRead(bytePins[i]) << i;
		}

		return b;
	}
	
	void writeBytes(unsigned char * b, unsigned short addr, int len){
		setBytePins(OUTPUT);
		for( int i=0 ; i < len ; i++){
			writeByte(b[i],(int)addr+i);
		}
	}
	
	void writeByte(unsigned char b, unsigned short addr){
		setAddr(addr);
		setByte(b);
		digitalWrite(CE, LOW);
		digitalWrite(WE, LOW);
		digitalWrite(WE, HIGH);
		digitalWrite(CE, HIGH);
	}
	
	void setAddr(unsigned short addr){
		doubleShiftOut(addr);
	}
	
	void setByte(unsigned char b){
		for(int i=0 ; i < 8 ; i++)
			digitalWrite(bytePins[7-i], b & (1<<i) );
	}
	
	void setup() {
	  //set pins to output so you can control the shift register
	  Serial.begin(9600);
	  pinMode(latchPin, OUTPUT);
	  pinMode(clockPin, OUTPUT);
	  pinMode(dataPin, OUTPUT);
	  
	  pinMode(CE, OUTPUT);
	  digitalWrite(CE, HIGH);   /// Add this
	  
	  pinMode(OE, OUTPUT);
	  digitalWrite(OE, HIGH);  /// Add this
	  
	  pinMode(WE, OUTPUT);
	  digitalWrite(WE, HIGH);
	  
	  //setBytePins(OUTPUT);
	}

	void loop() {
	
		unsigned char in_byte[4] = { 0xf1, 0x40, 0x41, 0xf0 };
		unsigned char out_byte[4] = { 1,2,3,4 };
		
		writeBytes(in_byte, 0x0, 4);
		readBytes(out_byte, 0x0, 4);

		Serial.print(out_byte[0], BIN);
		Serial.print(" ");
		Serial.print(out_byte[1], BIN);
		Serial.print(" ");
		Serial.print(out_byte[2], BIN);
		Serial.print(" ");
		Serial.println(out_byte[3], BIN);
		
		delay(500);
	}

	void doubleShiftOut(unsigned short b){
		unsigned char b1 = (b & 0xff00) >> 8;
		unsigned char b2 = b & 0xff;
		digitalWrite(latchPin, LOW);
		shiftOut(dataPin, clockPin, MSBFIRST, b1);
		shiftOut(dataPin, clockPin, MSBFIRST, b2);
		digitalWrite(latchPin, HIGH);
	}

It outputs 0 0 0 0 now.

I think it's reading ok but not writing anything due to the drop in voltage but that's just a guess.

The only strange things I see in the code now should not prevent it from working. You're probably right about the hardware (power) problem.

Notes:
CE was left LOW after readBytes(). Not a problem.
writeByte() was using the data pins in the opposite order from readByte(). Data would come out reversed but not zero.

You had a few places where a function called one function (setAddr()) or a small function was used in just one place. It's mostly a matter of style. You also had a few unnecessary temporary variables and casts.

Just to consolidate code a bit:

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
int bytePins[8] = {
  2,3,4,5,6,7,9,10};
int CE = A2;
int OE = A1;
int WE = A0;

void setup() {
  //set pins to output so you can control the shift register
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  pinMode(CE, OUTPUT);
  digitalWrite(CE, HIGH);  // DISABLED (active low signal) 

  pinMode(OE, OUTPUT);
  digitalWrite(OE, HIGH);  // DISABLED (active low signal)

  pinMode(WE, OUTPUT);
  digitalWrite(WE, HIGH);  // DISABLED (active low signal)
}

/*	mode: INPUT or OUTPUT
 		OUTPUT: for writing out to memory
 		INPUT: for reading from memory */
void setBytePins(int mode){
  for(int i=0 ; i < 8 ; i++){
    pinMode(bytePins[i], mode);
  }
}

void setAddr(unsigned short addr){
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, addr>>8);
  shiftOut(dataPin, clockPin, MSBFIRST, addr);
  digitalWrite(latchPin, HIGH);
}

void readBytes(unsigned char * buffer, unsigned short addr, int len){
  setBytePins(INPUT);
  digitalWrite(CE, LOW);
  digitalWrite(OE, LOW);
  for( int i=0 ; i < len ; i++){
    buffer[i] = readByte(addr+i);;
  }
  digitalWrite(OE, HIGH);
  digitalWrite(CE, HIGH);
}

unsigned char readByte(unsigned short addr){
  setAddr(addr);
  unsigned char b=0;
  for( int i=0 ; i < 8 ; i++ ){
    b |= digitalRead(bytePins[i]) << i;
  }
  return b;
}

void writeBytes(unsigned char * b, unsigned short addr, int len){
  setBytePins(OUTPUT);
  for( int i=0 ; i < len ; i++){
    writeByte(b[i],addr+i);
  }
}

void writeByte(unsigned char b, unsigned short addr){
  setAddr(addr);
  for(int i=0 ; i < 8 ; i++)
    digitalWrite(bytePins[i], b & (1<<i) );
  digitalWrite(CE, LOW);
  digitalWrite(WE, LOW);  // Initiate write
  digitalWrite(WE, HIGH);
  digitalWrite(CE, HIGH);
}

void loop() {
  unsigned char in_byte[4] = {0xf1, 0x40, 0x41, 0xf0};
  unsigned char out_byte[4] = {1, 2, 3, 4};

  writeBytes(in_byte, 0x0000, 4);
  
  readBytes(out_byte, 0x0000, 4);

  Serial.print(out_byte[0], BIN);
  Serial.print(" ");
  Serial.print(out_byte[1], BIN);
  Serial.print(" ");
  Serial.print(out_byte[2], BIN);
  Serial.print(" ");
  Serial.println(out_byte[3], BIN);

  delay(500);
}

The voltage shouldn't die like that, what are you using for a power supply?


Rob

The voltage shouldn't die like that, what are you using for a power supply?

I'm using the power supplied by usb on the Arduino (Duemilanove)

Could it be I've broken my chips in earlier tests? For example I didn't know it was bad to leave a chip unpowered while still having power on the data lines when I started out with this project.

Yeah, I broke my Arduino. Computer doesn't recognize it anymore.

edit: I was wrong. When I removed all the pins from the Arduino the computer picked it up again. I think I'll just rebuild the circuit from scratch using the schematic and try again (and use a different power source or powered usb hub).

.. I'm using Ramtron's FRAM FM25H20 - serial SPI, 8pin, 256kByte, spi_clk up to 40MHz, nonvolatile, works as SRAM (full r/w speed).. P.