Okay - Not got the 3 8-bit register stuff working, been playing around with Eagle and making schematics and related things.
But here's where the code is at for now.
I am controlling the address and control lines with Direct Port Manipulation. PORTA is the data lines(D0 - D7). PORTD is the lower 8 address lines (A0 - A7), PORTB is the middle 8 address lines (A8- A15) and PORTD is the upper 3 address lines and the Chip ENable lines (A16 - A18, !CE, !OE, !WE)
And here is the first part of the code, setuo and the shared functions -
/*
FlashProgrammer for
SST39SF010/020/040 series Flash Proms
010 - 131,072 bytes
020 - 262,144 bytes
040 - 524,288 bytes
This code should work with ATMega164/324/644/1284
*/
// PORTA is data bits 0-7
// PORTC is address bits 0-7
// PORTB is address bits 8-15
int AB16 = 10;
int AB17 = 11;
int AB18 = 12;
int ChipEN = 13;
int ReadEN = 14;
int WriteEN = 15;
void setup()
{
Serial.begin(115200);
// set control signals to HIGH, all are active LOW
pinMode(ChipEN,OUTPUT);
digitalWrite(ChipEN,HIGH);
pinMode(ReadEN,OUTPUT);
digitalWrite(ReadEN,HIGH);
pinMode(WriteEN,OUTPUT);
digitalWrite(WriteEN,HIGH);
// configure the address lines and set them all to LOW
DDRC = 255;
PORTC = 0;
DDRB = 255;
PORTB = 0;
pinMode(AB16,OUTPUT);
digitalWrite(AB16,0);
pinMode(AB17,OUTPUT);
digitalWrite(AB17,0);
pinMode(AB18,OUTPUT);
digitalWrite(AB18,0);
Serial.println();
Serial.println("SST39SF010/020/040 Flash Programmer");
}
// takes an address as an unsigned long and loads it into the address bits.
// when finished the address will be on the address lines and
// ChipEN, WriteEN, and ReadEN will be HIGH.
void LoadAddr(unsigned long AddressL)
{
unsigned long workAddrL;
unsigned int PDHold;
workAddrL = AddressL;
PORTC = lowByte(workAddrL);
PORTB = highByte(workAddrL);
PDHold = PORTD & 0xE3;
PDHold= PDHold |((workAddrL >> 14) & 0x1C);
PORTD = PDHold;
}
// takes an address and returns the byte at that address
// calls LoadAddr()
byte DoRead(unsigned long readAddr)
{
byte readVal;
unsigned int PDHold;
LoadAddr(readAddr);
DDRA = 0; // set port A as all inputs from Flash Data Lines
PORTA=0xFF;
PDHold = PORTD ; // save PORTD bits
PORTD = PDHold & 0x9F; // WriteEN HIGH, ChipEN & ReadEN LOW
delay(1); // let the signals settle
readVal = PINA; // Read the data
PORTD = PDHold; // Write the original value back to PORT D, All Enable bits high
return readVal;
}
// takes an unsigned long address and a byte and writes them to the Flash
// calls LoadAddr()
void DoWrite(unsigned long writeAddr, byte writeVal)
{
LoadAddr(writeAddr);
DDRA = 255; // set port A as all outputs to Flash Data Lines
PORTA = writeVal; // load the value to PORTA
PORTD = PORTD & 0x5F; // set ChipEN and WriteEN LOW
delay(1); // let the signals settle
PORTD = PORTD | 0xE0; // set ChipEN and WriteEN HIGH
}
// gets the device ID codes from the Flash.
// calls DoWrite() and DoRead()
void DeviceID()
{
byte WorkByte;
Serial.println();
Serial.println("Device Identification");
Serial.println();
DoWrite(0x5555L,0xAA); // First output byte of Software ID Entry
DoWrite(0x2AAAL,0x55); // Second output byte of Software ID Entry
DoWrite(0x5555L,0x90); // Third output byte of Software ID Entry
WorkByte = DoRead(0L); // Read address 0 for manufacturer ID
if (WorkByte == 0xBF)
{
Serial.println("Chip Manufactured by SST");
}
else
{
Serial.print("Unkmown manufacturer : ");
Serial.println(WorkByte,HEX);
}
WorkByte = DoRead(1L); // Read address 1 for Chip ID
if (WorkByte == 0xB5)
{
Serial.println("SST39SF010");
Serial.println("128Kx8 Device");
Serial.println("131,072 Bytes");
}
else if (WorkByte == 0xB6)
{
Serial.println(" SST39SF020");
Serial.println("256Kx8 Device");
Serial.println("262,144 Bytes");
}
else if (WorkByte == 0xB7)
{
Serial.println(" SST39SF040");
Serial.println("512Kx8 Device");
Serial.println("524,288 Bytes");
}
else
{
Serial.print(" Unknown Device : ");
Serial.println(WorkByte,HEX);
}
Serial.println();
DoWrite(0x5555L,0xF0); // Exit ID Mode
}
// print an unsigned long as 5 HEX digits
void PrintHex5(unsigned long PrintVal)
{
Serial.print((PrintVal >> 16) & 0xF,HEX);
Serial.print((PrintVal >> 12) & 0xF,HEX);
Serial.print((PrintVal >> 8) & 0xF,HEX);
Serial.print((PrintVal >> 4) & 0xF,HEX);
Serial.print(PrintVal & 0xF,HEX);
}
// take 5 HEX digits and convert to unsigned long
unsigned long Asc52Long(char *srcStr)
{
int ctr;
int tmpChar;
unsigned long tmpLong = 0L;
for (ctr = 0; ctr < 5; ctr++)
{
tmpChar = srcStr[ctr];
tmpChar = tmpChar & 0x4F;
if (tmpChar > 9)
{
tmpChar = (tmpChar & 0xF) + 9;
}
tmpLong = (tmpLong << 4) + tmpChar;
}
return tmpLong;
}
// take 2 hex digits and convert to byte
byte Asc22Byte(char *srcStr)
{
int ctr;
char tmpChar;
char workChar = 0;
for (ctr = 0; ctr < 2 ; ctr++)
{
tmpChar = srcStr[ctr];
tmpChar = tmpChar & 0x4F;
if (tmpChar > 9)
{
tmpChar = (tmpChar & 0xF) + 9;
}
workChar = (workChar << 4) + tmpChar;
}
return workChar;
}

