使用arduino制作并行闪存编程器的问题

时间:2015-07-25 23:11:19

标签: parallel-processing arduino flash-memory

我有一个非常大的项目,这是一小部分,但同样重要。我有一个由SST和Microchip制造的并行闪存芯片(有点令人困惑),并且在绕过写保护时遇到了麻烦。我正在使用arduino mega来编程,因为我没有时间等待程序员从中国发货。这是闪存的数据表:http://ww1.microchip.com/downloads/en/DeviceDoc/25022B.pdf

void setup() {
  Serial.begin(19200);
  pinMode(A8,OUTPUT);//OE#
  pinMode(A9,OUTPUT);//WE#

  for(byte i=0;i<15;i++) //15 bit address bus
    pinMode(i+20, OUTPUT);
  for(byte i=0;i<8;i++)  //8 bit bidirectional data bus
    pinMode(i+40, OUTPUT);
  wrt(0xAA,0x5555);// erase sector 0 to 0xFF
  wrt(0x55,0x2AAA);
  wrt(0x80,0x5555);
  wrt(0xAA,0x5555);
  wrt(0x55,0x2AAA);
  wrt(0x30,0);
  delay(250);
  wrt(0xAA,0x5555);// write byte 0 to 3
  wrt(0x55,0x2AAA);
  wrt(0xA0,0x5555);
  wrt(0x03,0);
  delay(1000);
  Serial.println("reading....");
  for(int i=0;i<16;i++)// read data
    rd(i);
}

void loop();
void wrt(byte var, int loc){
  datbusout();// set data bus to output mode
  digitalWrite(20,HIGH&&(loc&1));
  digitalWrite(21,HIGH&&(loc&2));
  digitalWrite(22,HIGH&&(loc&4));
  digitalWrite(23,HIGH&&(loc&8));
  digitalWrite(24,HIGH&&(loc&16));
  digitalWrite(25,HIGH&&(loc&32));
  digitalWrite(26,HIGH&&(loc&64));
  digitalWrite(27,HIGH&&(loc&128));
  digitalWrite(28,HIGH&&(loc&256));
  digitalWrite(29,HIGH&&(loc&1024));
  digitalWrite(30,HIGH&&(loc&2048));
  digitalWrite(31,HIGH&&(loc&4096));
  digitalWrite(32,HIGH&&(loc&8192));
  digitalWrite(33,HIGH&&(loc&16384));
  digitalWrite(34,HIGH&&(loc&32768));
  for(int i=40;i<48;i++)
    digitalWrite(i,HIGH&&(var&(1<<i)));
  PORTK=1;// write mode
  Serial.println(var,HEX);
  delayMicroseconds(20);
  PORTK=3;// set OE# and WE# high
}
void rd(int loc){
  datbusinp();
  byte out=0;
  digitalWrite(20,HIGH&&(loc&1));
  digitalWrite(21,HIGH&&(loc&2));
  digitalWrite(22,HIGH&&(loc&4));
  digitalWrite(23,HIGH&&(loc&8));
  digitalWrite(24,HIGH&&(loc&16));
  digitalWrite(25,HIGH&&(loc&32));
  digitalWrite(26,HIGH&&(loc&64));
  digitalWrite(27,HIGH&&(loc&128));
  digitalWrite(28,HIGH&&(loc&256));
  digitalWrite(29,HIGH&&(loc&1024));
  digitalWrite(30,HIGH&&(loc&2048));
  digitalWrite(31,HIGH&&(loc&4096));
  digitalWrite(32,HIGH&&(loc&8192));
  digitalWrite(33,HIGH&&(loc&16384));
  digitalWrite(34,HIGH&&(loc&32768));
  PORTK=2;
  delayMicroseconds(1); // wait for read to finish
  for(int i=0;i<8;i++)
    out|=digitalRead(40+i)<<i;
  PORTK=3;
  Serial.println(out,HEX);
}
void datbusinp(){
  DDRG&=252;// did the same thing like this, just faster
  DDRL&=3;
}
void datbusout(){
  DDRG|=3;
  DDRL|=252;// see last comment 
}

2 个答案:

答案 0 :(得分:1)

for(int i=40;i<48;i++)
    digitalWrite(i,HIGH&&(var&(1<<i)));

这是错的,当然?

你至少向左移动了40次,这意味着你总是写一个零。

答案 1 :(得分:0)

I fixed it!!!! so I accidentally had the wrong values for anding when writing to the address bus. A TON of thanks to Nick Gammon, test would have failed today without him. more about the answer: I needed to change my for loop in the wrt function, and not skip 512 when writing to the address bus. :D code:

  digitalWrite(20,HIGH&&(loc&1));
  digitalWrite(21,HIGH&&(loc&2));
  digitalWrite(22,HIGH&&(loc&4));
  digitalWrite(23,HIGH&&(loc&8));
  digitalWrite(24,HIGH&&(loc&16));
  digitalWrite(25,HIGH&&(loc&32));
  digitalWrite(26,HIGH&&(loc&64));
  digitalWrite(27,HIGH&&(loc&128));
  digitalWrite(28,HIGH&&(loc&256));
  digitalWrite(29,HIGH&&(loc&1024));
  digitalWrite(30,HIGH&&(loc&2048));
  digitalWrite(31,HIGH&&(loc&4096));
  digitalWrite(32,HIGH&&(loc&8192));
  digitalWrite(33,HIGH&&(loc&16384));
  digitalWrite(34,HIGH&&(loc&32768));

needed to become

  digitalWrite(20,HIGH&&(loc&1));
  digitalWrite(21,HIGH&&(loc&2));
  digitalWrite(22,HIGH&&(loc&4));
  digitalWrite(23,HIGH&&(loc&8));
  digitalWrite(24,HIGH&&(loc&16));
  digitalWrite(25,HIGH&&(loc&32));
  digitalWrite(26,HIGH&&(loc&64));
  digitalWrite(27,HIGH&&(loc&128));
  digitalWrite(28,HIGH&&(loc&256));
  digitalWrite(29,HIGH&&(loc&512));
  digitalWrite(30,HIGH&&(loc&1024));
  digitalWrite(31,HIGH&&(loc&2048));
  digitalWrite(32,HIGH&&(loc&4096));
  digitalWrite(33,HIGH&&(loc&8192));
  digitalWrite(34,HIGH&&(loc&16384));