Reading MaskROM with a microcontroller

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Reading MaskROM with a microcontroller
by on (#112134)
I'm trying to read a MaskROM that has been removed from a cart using a Teensy++ 2.0 microcontroller board. The Teensy++ 2.0 has a ton of I/O pins, enough for a 1:1 connection to the MaskROM. However, I'm having issues doing the reading. I couldn't find a timing diagram for the MaskROM I/O, so I used the diagrams from the AM29F032B datasheet, since I know they work in repros. Here's the diagram for a read operation:

Image

And here's my code

Code:
void Init()
{
  // Address lines as outputs
  A7_0_DDR   = 0xFF;
  A15_8_DDR  = 0xFF;
  A22_16_DDR = 0x7F;
 
  // Data line defaults to input (read mode)
  DATA_DDR   = 0x00;
 
  // Control lines as outputs, pulled high
  CONTROL_PORT |= (CS_BIT | OE_BIT | WE_BIT | RST_BIT);
  CONTROL_DDR  |= (CS_BIT | OE_BIT | WE_BIT | RST_BIT);
}

uint8_t ReadByte(uint32_t address){
  CONTROL_PORT |= WE_BIT;
 
  A7_0_PORT   = address & 0xFF;
  A15_8_PORT  = (address >> 8) & 0xFF;
  A22_16_PORT = (address >> 16) & 0x7F;
 
  CONTROL_PORT &= ~CS_BIT;
  CONTROL_PORT &= ~OE_BIT;
 
  uint8_t data = DATA_PORT;

  CONTROL_PORT |= OE_BIT;
  CONTROL_PORT |= CS_BIT;
  CONTROL_PORT &= ~WE_BIT;
 
  return data;
}


Basically, my main is just calling Init(), then calling ReadByte in a loop with incrementing addresses starting at 0, then printing the result to the serial line. All of the *_PORT and *_BIT names are #define'd in my header, and I've double-checked that the #define's match my connections. I've even added busy waits between each command, but it doesn't help. All I get back are 0x00 over and over. I have a feeling I'm just doing something really stupid, but I don't know what it might be... any ideas?
Re: Reading MaskROM with a microcontroller
by on (#112135)
I don't think you should need to do anything with the /WE line, but that shouldn't be causing the problems you're seeing.

At this point I'd probably resort to LED or 'scope debugging to make sure that my code does what I believe it does.
Re: Reading MaskROM with a microcontroller
by on (#112136)
Yeah, I'll probably have to go with LED's... that's way too many I/O lines to get anything useful from an Oscilloscope...
Re: Reading MaskROM with a microcontroller
by on (#112143)
You can get all kinds of info from a single oscope probe. They're really good it showing you things like conflicting data busses and such in real time. I'm not familiar with the teensy definitions, but it looks pretty choose to the avr definitions. With that I'd assume "DATA_PORT" is an output reg, and something like "DATA_PIN" is your input reg. You should use the input ref for reading, looks like you're using the output reg.
Re: Reading MaskROM with a microcontroller
by on (#112147)
The Teensy is an AVR. Good call on the inputs being PIN_ rather than PORT_, I think that did it... Now I'm getting results that look reasonable, but are wrong about 50-60% of the time. It may be a bad socket connection or something, but hey, real results, that's a start :)

Edit: It looks like it's a single bit giving me problems (i.e. reading 0x0F when it should be 0x07, it seems to be a consistent issue with D3), so it has to be the connection. Thanks for the tip!
Re: Reading MaskROM with a microcontroller
by on (#112150)
Putting the sockets on opposite sides of the board effectively cut the PCB size in half (as well as cutting the cost in half as well). Made the tracing a bit tricky, but I managed to do it with 0 vias :)

Image
Image