Pages: 1 [2]   Go Down
Author Topic: Problems with parallel sram  (Read 2463 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8458
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think this looks a bit sus

Code:
b |= digitalRead(bytePins[i] << i);

try

Code:
b |= digitalRead(bytePins[i]) << i;

Also in principle I don't think it's good to leave CE low while the address lines are changing,

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

void writeByte(unsigned char b, unsigned short addr){
setAddr(addr);
setByte(b);
digitalWrite(WE, LOW);
digitalWrite(WE, HIGH);
}

I'd move the CE stuff to the writeByte() func

Code:
void writeByte(unsigned char b, unsigned short addr){
setAddr(addr);
setByte(b);
                digitalWrite(CE, LOW);
digitalWrite(WE, LOW);
digitalWrite(WE, HIGH);
                digitalWrite(CE, LOW);
}

______

Rob

« Last Edit: July 17, 2011, 07:01:41 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just for fun I looked at the chip specification:

http://media.digikey.com/pdf/Data%20Sheets/Cypress%20PDFs/CY62256%20(Jul05).pdf

It looks like you can leave CE set to LOW all the time without ill effects.   Use OE LOW for reading and WE LOW for writing.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8458
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep I just looked at the data sheet, it seems that it's OK to even leave CE low permanently. I still prefer to keep such things together in one function, but that's as much a style issue as anything. Meaning that a function called writeByte() should do everything involved in writing a byte. On a larger program someone may call writeByte() directly one day and wonder why it didn't work.

Admittedly if speed is an issue the current code will be faster and this is a very small program, it's easy to see what's happening as the CE code is just a few  lines above.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think it's not functioning properly due to there being a drop in voltage on the bus though. Any ideas on what might be causing that?

The datasheet says it can only operate at 4.5v minimum and I'm reading 4.36v on the bus even though it's fed by a 5v source.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8458
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you look at the code I think is wrong?

You also need to find out where 5v turns into 4.36v. Measure at the source, if it's good there then work down the line until it goes bad.

If it's bad at the source unplug the ram and see if things change. Do you have 5v with no ram? If so then the ram chip may be at fault. If it doesn't change then the PSU is at fault.

Do you only get this voltage when running your sketch? If you run a blank sketch does it still show 4.36v?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: July 18, 2011, 07:23:46 am by RolfvDam » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Did you look at the code I think is wrong?

Here's the updated code:

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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;

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);
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8458
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
« Last Edit: July 20, 2011, 07:43:26 pm by RolfvDam » Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 53
Posts: 1990
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

.. 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.
Logged

Pages: 1 [2]   Go Up
Jump to: