Hi,
I was hoping for a bit of help with a project I'm working on. I'm trying to build a computer based on a 65C02 processor. What I'm planning to do is to use just SRAM in the system and load programs in from an ATMega1284P, which will then provide some simple IO (eventually).
I was making some good progress, but then I got stuck with getting the memory to work properly. I've stripped the whole thing back to just the microcontroller and the RAM chip, and for debugging I've cut off half the address bus as per the schematic (SRAM chip is powered, LEDs have current limiting resistors and are connected to ground!).
I've connected all 3 of the control signals to the MCU as well because I was struggling with getting the timing to work. The MCU is running at 1MHz. Everything is currently built on breadboards.
According to the datasheet for the SRAM, data will be written on the upwards transition of the WE# pin, as long as the address has been valid for 50 nanoseconds, and then the data is valid on the data bus for 25 nanoseconds.
I have created a function to write a byte to an address:
void write_byte(uint8_t addr, uint8_t data) { PORTB = 0b00001101; // WE off, OE off, CS off DDRC = 0xff; // Set data bus for output PORTA = addr; // Set address on address bus PORTC = data; // Set data on data bus PORTB = 0b00000100; // pulse WE for (uint8_t i=0;i<50;i++) // I know this isn't really 50ns, but it shouldn't matter? __asm("nop"); // 1 cycle (1ns?) PORTB = 0b00001101; // Set everything back off }
I've then written some very simple code to load RAM with some values, and then read them back and display them on the LEDs:
for(uint8_t a=0 ; a<255 ; a++) { if (a%2) { write_byte(a, 0xe7); } else { write_byte(a, 0x7e); } } ... uint8_t b = 0; for(uint8_t a=0 ; a<255 ; a++) { b = read_byte(a); PORTD = b; delay(10); PORTD = 0; delay(10); }
Unsurprisingly, this doesn't work. The first 20 or so bytes appear to be written correctly, along with quite a few others along the way, but there's a lot of random junk dumped in the RAM.
As ever, I'm doing something stupid and I'm out of my depth. I'd gotten further than this and had the 65C02 hooked up and the 1284P was writing a small program which the 65C02 was happily executing, but it couldn't write anything to the RAM reliably.
I stripped it all back and discovered that my write function does not work as I hoped.
I would appreciated any help anyone might be able to give.
Thanks
-Mike