hey folks.
I'm currently trying to read the contents of an old audio board to my hard drive. It's interleaved across two 64 mbit (4mx16 WORD) chips. I've managed to put together an adapter to read it with the MEGA, and have had some success, but after the first 256k are read, it loops around.
Now I am aware that this is likely to do with using an "int" to count my address space, but when I move to something like an uint32_t, it seems to no longer read the data on the board properly. At least with the first approach I'm getting some readable data, even if it's very minimal.
Can someone point me in the right direction? I am extremely green with this stuff, so I am really hoping I'm just missing something painfully obvious.
// Set pin definitions for address and data
// first half are chip one (d0-d15), second half are chip two (d16-d31)
int dataPinsAll[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 8, 9, 10, 11, 12, 13, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
// address pins are the same on both chips - A0-A21
int addressPinsA0_A21[] = {38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 2, 3, 4, 5, 6, 7}; // combined address pins
// OE (A10) and CE (A11) pins
const int pinOE = A10;
const int pinCE = A11;
bool startReading = false; // starting flag for serial read
void setup() {
// Set all address lines as outputs
for (int i = 0; i < 22; i++) {
pinMode(addressPinsA0_A21[i], OUTPUT);
}
// Set data lines as inputs
for (int i = 0; i < 32; i++) {
pinMode(dataPinsAll[i], INPUT_PULLUP);
}
// Set OE and CE as outputs
pinMode(pinOE, OUTPUT);
pinMode(pinCE, OUTPUT);
// Set OE and CE to HIGH (inactive state)
digitalWrite(pinOE, HIGH);
digitalWrite(pinCE, HIGH);
delay(100);
Serial.begin(115200);
}
void SetAddress(int addr) {
// Set all 22 bits of the address (A0-A21)
for (int i = 0; i < 22; i++) {
digitalWrite(addressPinsA0_A21[i], (addr & (1 << i)) ? HIGH : LOW);
}
}
uint32_t ReadData() {
uint32_t data = 0;
// Loop through the 32 data pins and construct the 32-bit word
for (int i = 0; i < 32; i++) {
if (digitalRead(dataPinsAll[i]) == HIGH) {
data |= (1UL << i); // Set the corresponding bit if the pin is HIGH
}
}
return data;
}
void waitForStartCommand() {
// Wait until the word "start" is received via serial
while (!startReading) {
// Check if the 'start' signal has been received
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n'); // Read until a newline character
command.trim(); // Remove any leading/trailing whitespace
if (command == "start") {
startReading = true; // Set flag to start reading
Serial.println("Start signal received, reading memory...");
}
}
delay(10); // Small delay to avoid flooding serial communication
}
}
#define MAX_ADDR 16000000L // 16MB address space (for the 8M x 32 SIMM configuration)
#define BUFFER_SIZE 64 // seems to be abotu right
void loop() {
waitForStartCommand(); // wait for start
uint32_t combinedWord;
int addr;
uint8_t buffer[BUFFER_SIZE];
int bufferIndex = 0;
// Read from both U1 and U2, combining into 32-bit words
for (addr = 0; addr < MAX_ADDR; addr++) { // Read each address for U1 and U2
// Set address before enabling the chip
SetAddress(addr);
// Wait for the address to settle (1 µs delay is safe)
delayMicroseconds(1);
// Enable OE and CE to read data
digitalWrite(pinOE, LOW);
digitalWrite(pinCE, LOW);
// Wait for tOE to ensure the data is ready (50 ns minimum, 1 µs is safe)
delayMicroseconds(1);
// Read the 32-bit data word from all data lines
combinedWord = ReadData();
// Disable OE and CE after reading
digitalWrite(pinOE, HIGH);
digitalWrite(pinCE, HIGH);
// Correct the byte order for output
buffer[bufferIndex++] = (combinedWord >> 8) & 0xFF; // MSB of U1 (Byte 2)
buffer[bufferIndex++] = combinedWord & 0xFF; // LSB of U1 (Byte 1)
buffer[bufferIndex++] = (combinedWord >> 24) & 0xFF; // MSB of U2 (Byte 4)
buffer[bufferIndex++] = (combinedWord >> 16) & 0xFF; // LSB of U2 (Byte 3)
// If the buffer is full, send the data via Serial
if (bufferIndex >= BUFFER_SIZE) {
Serial.write(buffer, BUFFER_SIZE); // Send buffer data
bufferIndex = 0; // Reset buffer index
}
}
// Flush remaining data in the buffer if any
if (bufferIndex > 0) {
Serial.write(buffer, bufferIndex);
}
// Add a 5-second delay after the entire board has been read
delay(5000);
// Send a Serial disconnect signal (optional custom message)
Serial.println("DISCONNECT"); // Signal to the host that reading is complete
// Close the Serial connection
Serial.end(); // This ends the serial communication
}
Thanks for listening!