Page 1 of 2

6522 doesn't register input

Posted: Sun Oct 26, 2025 10:12 pm
by technifix
Good afternoon!

I've finally gotten back to building 6502 SBCs. I've run into an issue that is boggling my mind. I've been trying to fix it for two weeks and I've been losing sleep.

My current design uses a WDC 6522 to bit-bang SPI to a MAX3100 UART. I've had this working without issue in the past. I'm thinking the problem must be really simple and I'm overlooking something incredibly obvious.

Using port A, I've set bit 0 to SCLK, bit 1 to MISO, bit 2 to CS, and bit 7 to MOSI. I have absolutely no problem sending the write configuration bytes, and I can send text to my PC. Apparently I have the baud rate set correctly. The issue is I can't read anything. Bit 7 is ALWAYS 0. I've scoped it and the 3100 sets the bit to 1, and I can probe that 1 at the 6522, but no matter what I do it doesn't show up when I read port A.

I've re-wired it to use port B, no dice. I wrote my transmit routine to wait until the transmit buffer is empty (indicated by the second bit returned when sending any command, I'm using read config 0, 1), but since the transmit buffer empty is indicated with a 1, it never leaves the loop. If I run it with a slow clock (approx 600Hz) and leave out the buffer empty check it transmits fine, but I can't receive anything either.

I've also hooked the 3100 to an arduino and it works without issue. I made certain that the DDR was set correctly by setting it every call to the buffer empty check, even though I'm sure it wasn't changed from initialization. I set the DDR to %01111111, marking bit 7 as input.

Code: Select all

SPI_transmitempty: ; returns 1 if transmit buffer is empty
  phy
  
  lda #%00111111 ; XXX DEBUG: make certain pin 7 is an input
  sta DDRA       ; XXX
  
  ldy #MISO    ; bit 1 high
  stz PORTA ; 0 SPI_start
  inc PORTA
  dec PORTA ; first bit is receive buffer empty bit - don't care
  sty PORTA ; 1 (Read Config)
  inc PORTA ; Transmit buffer bit should be at pin 7 MISO
  bit PORTA
  bpl .90   ; if T is 0 (pin 7 is 0) go to .90
   ; It's not getting here for some reason..
  lda #$01
  ;bra .91
 .90:
  ;lda #1 ; DEBUG
 ;.91:
  dec PORTA ; Accumulator should now be zero or one. Finish operation.
  ldy #CS
  sty PORTA ; SPI_end
  ply
  rts
I also switched it to bit 6 and used bvc but I got the same result. I'm at a loss. My SBC is on a PCB, so I can't wire in a DIP 6522 (I'm using a PLCC), but I can't imagine the chip is bad - everything else seems to work. Also I didn't need that BIT instruction before. The inc instruction was enough to set the negative flag.

I also just tried manually using an LED to follow an input pin:

Code: Select all

reset:
 ldx #$FF
 txs
 
 lda #$FF
 sta DDRB
 lda #$7F
 sta DDRA
 
 ldx #1
 stz PORTB

test:
 bit PORTA
 bpl t1
 stz PORTB
 bra t2
t1:
 stx PORTB
t2:
 jmp test
I can flash the LED by writing to it directly, but it won't follow the input. I used LDA instead of BIT too.

Hopefully this post wasn't too scatterbrained. My migraine isn't helping. If you have any ideas, please let me know! The oscilloscope shows signals that make complete sense. I"m positive the 3100 is working. I've read the datasheet and I tried setting the ACR so latching is disabled, and I've disabled IRQs just in case they could've been an issue, both on the 6522 and the 3100. I want to implement a Rx IRQ but that's pointless right now.

I'm going to go take some Tylenol. I hope everyone is well!
Steve

Re: 6522 doesn't register input

Posted: Sun Oct 26, 2025 10:31 pm
by GARTHWILSON
technifix wrote:
I've set bit 0 to SCLK, bit 1 to MISO, bit 2 to CS, and bit 7 to MOSI.
Is this just a error in writing the post?  Your code wants bit 7 to be MISO (master-in / slave-out), not MOSI.

Edit:  See if my code at viewtopic.php?p=90041#p90041 helps.

Do get well.

Re: 6522 doesn't register input

Posted: Mon Oct 27, 2025 7:32 am
by JohanFr
Edit(Moved to top as it is my prime suspect issue) If your LED setup is causing you trouble I would double check the port constants so that you haven't mixed up DDR or PORT etc. For example, mixing up DDR and PORT would make the LED flash if you have set your output to 1 and toggle the DDR pin, but reading the DDR would just read the state of the DDR, whatever it was set to.

Be sure to double check the CS and clock output from the 6522 as well and that they are wired to the correct pin on the MAX3100. And that your constants DDRA and PORTA are correct.

Also note that DOUT on the MAX3100 means data out from the MAX3100 to the host, not data out to the outer world.

Iirc the state of the RTS pin might play a role as well but that is probably a later problem.

Edit2: Also the obvious, are you sure you are at the right pins on the 6522, i.e. physical leg on the chip?

Re: 6522 doesn't register input

Posted: Mon Oct 27, 2025 1:11 pm
by BigDumbDinosaur
First thing is to post a schematic of your unit.  The drawing doesn’t have to be elaborate, just clear...and in monochrome.  :D

A mistake occasionally seen with this sort of thing is using the Ø2 clock to qualify the 65C22’s chip select and read/write inputs.  That is incorrect design and depending on signal skew, the phase of the moon and the state of the stock market, may result in intermittent or no operation.

Re: 6522 doesn't register input

Posted: Mon Oct 27, 2025 5:08 pm
by Yuri
BigDumbDinosaur wrote:
That is incorrect design and depending on signal skew, the phase of the moon and the state of the stock market, may result in intermittent or no operation.
Does it mater if it's a bull market or a bear market?

(Sorry, couldn't resist. :mrgreen: )

Re: 6522 doesn't register input

Posted: Sun Nov 02, 2025 7:33 pm
by technifix
Thanks for all of the replies! I grabbed the relevant part of the schematic and made it greyscale.
GARTHWILSON wrote:
technifix wrote:
I've set bit 0 to SCLK, bit 1 to MISO, bit 2 to CS, and bit 7 to MOSI.
Is this just a error in writing the post? Your code wants bit 7 to be MISO (master-in / slave-out), not MOSI.

Edit: See if my code at viewtopic.php?p=90041#p90041 helps.

Do get well.
It is an error in my constant naming. I have it backwards but I don't actually reference MOSI anywhere. In my schematic I have PA1 connected to DIN and PA7 connected to DOUT, which I believe is correct. It does transmit fine.
JohanFr wrote:
Edit(Moved to top as it is my prime suspect issue) If your LED setup is causing you trouble I would double check the port constants so that you haven't mixed up DDR or PORT etc. For example, mixing up DDR and PORT would make the LED flash if you have set your output to 1 and toggle the DDR pin, but reading the DDR would just read the state of the DDR, whatever it was set to.

Be sure to double check the CS and clock output from the 6522 as well and that they are wired to the correct pin on the MAX3100. And that your constants DDRA and PORTA are correct.

Also note that DOUT on the MAX3100 means data out from the MAX3100 to the host, not data out to the outer world.

Iirc the state of the RTS pin might play a role as well but that is probably a later problem.

Edit2: Also the obvious, are you sure you are at the right pins on the 6522, i.e. physical leg on the chip?
Here are my port contants:

Code: Select all

PORTB = $D000
PORTA = $D001
DDRB  = $D002
DDRA  = $D003
ACR   = $D00B
IFR   = $D00D
IER   = $D00E

SCLK = %00000001
MISO = %00000010
CS   = %00000100
MOSI = %10000000
I have also included a shot from my oscilloscope. Unfortunately it's only a two channel, so it only has DOUT and SCLK, DOUT is yellow(top) and SCLK is blue(bottom). The pulses in the centre are correct- the short blue pulse clocks past the first bit (receive buffer is empty, which is represented by a low), which when SCLK goes low causes DOUT to immediately go high, which seems to indicate I don't have to actually toggle SCLK again to get the state of the transmit buffer since it goes high right after I send SCLK low. That's not how it's coded, so the second longer SCLK pulse is like that because while SCLK is high I'm checking to see if DOUT/PA7 is high and branching. DOUT is high, but reading PA7 gives me a 0 (I took that shot with the probe on PA7). I then set CS high (which the 3100 datasheet says cancels/disregards whatever it was reading).


I hope this clarifies(?) anything I may have missed.

Re: 6522 doesn't register input

Posted: Sun Nov 02, 2025 8:12 pm
by BigDumbDinosaur
technifix wrote:
Thanks for all of the replies...

This doesn’t directly relate to the problem you are having, but what is debouncing the NMI push button?

I should mention that posting a fragment of the schematic is not usually helpful for others trying to help you debug.  Let’s see the whole enchilada.

Re: 6522 doesn't register input

Posted: Sun Nov 02, 2025 8:59 pm
by technifix
BigDumbDinosaur wrote:
technifix wrote:
Thanks for all of the replies...

This doesn’t directly relate to the problem you are having, but what is debouncing the NMI push button?

I should mention that posting a fragment of the schematic is not usually helpful for others trying to help you debug. Let’s see the whole enchilada.
It isn't populated right now. It has a 3.3k resistor to 5V.

I've added the entire schematic.

Thanks!
Steve

Re: 6522 doesn't register input

Posted: Sun Nov 02, 2025 11:12 pm
by BigDumbDinosaur
technifix wrote:
BigDumbDinosaur wrote:
technifix wrote:
Thanks for all of the replies...

This doesn’t directly relate to the problem you are having, but what is debouncing the NMI push button?
It isn't populated right now. It has a 3.3k resistor to 5V.
In my POC units, I use a DS1813 to debounce /NMI.  The firmware intercepts the NMI and if it is generated while the MPU was running a RAM-based program, the program will be interrupted and the M/L monitor will take control.  It’s a handy way to break a runaway loop without losing the environment.

Quote:
I've added the entire schematic.

That adds context to what you are doing.

A couple of things, not meant to be criticism, but to make it easier to deduce what your device is supposed to do.

Devices such as U5, U6 and U7, which are generic logic with multiple but otherwise identical gates, should be drawn out as individual gates instead of as rectangles with pin designations.  For example, someone might not know that U7 is a trio of triple-input NANDs and hence would be clueless about the device’s purpose.  However, if drawn with the individual gates, that someone will immediately understand, assuming they know standard logic symbology.

Rectangles-with-pin-designations are best used for devices that are not easily drawn out as gates, e.g., a bus transceiver, or are specialized in some way, e.g., a UART.  For those, it is common practice to, if possible, put all the input pins on one side of the rectangle, all the output pins on the other side, and put VCC at the top and ground at the bottom.  Attempting to recreate the shape of the device’s package as you are doing with U1 and U11 only complicates reading the schematic and may mistakenly convey the impression that the pin-out is specific to that package (the QFP and PLCC versions of U1 and U11 have the same pin-outs).

To illustrate what I mean, here is the glue logic for my POC V1.3 unit:

pocv130_glue.pdf
POC V1.3 Glue Logic
(81.03 KiB) Downloaded 60 times

It’s best to be sparing in your use of net symbols.  If possible, “wire up” things to make it easier to determine what is connected to what.  In my schematics, which often run to multiple pages, I mostly use net symbols to continue a circuit from one page to another, such as in this full schematic for POC V1.3:

pocv130.pdf
POC V1.3 Full Schematic
(344.54 KiB) Downloaded 62 times

By avoiding net symbols for connections on the same page, the casual reader is less likely to miss something.

I see 74F logic in there.  Is that what you are using?

Also, you have several floating inputs on U7.  That’s a no-no with CMOS logic.

Lastly, what is your memory map?

Re: 6522 doesn't register input

Posted: Mon Nov 03, 2025 12:06 am
by technifix
Quote:
In my POC units, I use a DS1813 to debounce /NMI. The firmware intercepts the NMI and if it is generated while the MPU was running a RAM-based program, the program will be interrupted and the M/L monitor will take control. It’s a handy way to break a runaway loop without losing the environment.
This was my plan. As you see from my missing some floating inputs, I didn't finish going through the whole thing. I can't believe I missed that. The others are wired fine. I have googled some info that has some conflicting opinions. Some say LS logic can float, others say it needs to be tied up (apparently it uses a bit less power to tie them to 5V as opposed to ground). Others say tie them up with resistors. I suppose it's best to tie them up somehow so you can be certain they aren't oscillating.
Quote:
That adds context to what you are doing.

A couple of things, not meant to be criticism, but to make it easier to deduce what your device is supposed to do.
I've done descriptive gates on some schematics. To be honest I never thought I'd be sharing it with anyone. I know what the chips do so it wasn't really an issue for me, but I can definitely see how it would hamper things when looked at by others. I also just used the symbols that EasyEDA provided.

Oh, and I have no issues with constructive criticism.
Quote:
By avoiding net symbols for connections on the same page, the casual reader is less likely to miss something.

I see 74F logic in there. Is that what you are using?
The reason I use netlabels liberally is I've always found it to be a huge pain to wire out a schematic and not have it look like a huge mess. I've never gotten bus wiring to work, ever. Perhaps I should try KiCad.

All of the logic is F series. I just never changed the part labels on the schematic.

Thanks for the links, I'll check them out.

Steve

Re: 6522 doesn't register input

Posted: Mon Nov 03, 2025 12:13 am
by technifix
I forgot the memory map.

$E000-$FFFF ROM
$D000-$DFFF IO

Everything else is RAM. I have a bunch of nice UM61512's that are fast and work great.

Steve

Re: 6522 doesn't register input

Posted: Mon Nov 03, 2025 1:31 am
by 8BIT
Hi Steve,

Unless I'm missing something, it looks like RAMOE is just the inverse of ROMOE. If that is true, then RAMOE is low for $0000-$DFFF. Your IO is also low during $D000-$DFFF. This may be why your IO reads are not working. RAMOE needs to be from $0000 to $CFFF only.

Daryl

Re: 6522 doesn't register input

Posted: Mon Nov 03, 2025 2:51 am
by BigDumbDinosaur
technifix wrote:
As you see from my missing some floating inputs...I have googled some info that has some conflicting opinions. Some say LS logic can float, others say it needs to be tied up (apparently it uses a bit less power to tie them to 5V as opposed to ground). Others say tie them up with resistors. I suppose it's best to tie them up somehow so you can be certain they aren't oscillating.

74LS inputs can be floated without detriment, but it’s probably better to tie unused inputs to one rail or the other, depending on how the device is being used.

CMOS inputs should never be floated unless the data sheet says otherwise.  If you think you might want to use a currently unused CMOS input sometime in the future, I suggest you pull it up to VCC—3.3K is usually a good value.

Quote:
All of the logic is F series. I just never changed the part labels on the schematic.

74F logic is level-incompatible with CMOS devices, other than 74xCT.  Also, 74F logic is a power hog.  I suggest you stick with 74HC(T) and avoid the logic level blues.

Re: 6522 doesn't register input

Posted: Mon Nov 03, 2025 2:55 am
by BigDumbDinosaur
8BIT wrote:
Unless I'm missing something, it looks like RAMOE is just the inverse of ROMOE. If that is true, then RAMOE is low for $0000-$DFFF. Your IO is also low during $D000-$DFFF. This may be why your IO reads are not working. RAMOE needs to be from $0000 to $CFFF only.

Having seen the memory map and looked at the glue logic, I concur.  There is a major contention issue if I/O is selected.

Re: 6522 doesn't register input

Posted: Sat Nov 08, 2025 3:01 pm
by technifix
8BIT wrote:
Hi Steve,

Unless I'm missing something, it looks like RAMOE is just the inverse of ROMOE. If that is true, then RAMOE is low for $0000-$DFFF. Your IO is also low during $D000-$DFFF. This may be why your IO reads are not working. RAMOE needs to be from $0000 to $CFFF only.

Daryl
This makes complete sense. I guess it's time to redo or rethink that part of the logic.
Quote:
74F logic is level-incompatible with CMOS devices, other than 74xCT. Also, 74F logic is a power hog. I suggest you stick with 74HC(T) and avoid the logic level blues.
Is HC logic fast enough for 14MHz+ operation? One of my goals was to eventually have a small ROM read a small routine from an sdcard, jump there, disable the rom and clock stretching circuitry and copy a second stage kernel to upper RAM. I didn't want to have a ROM copy circuit (although I guess the clock stretch circuit adds enough components that only run for an instant). Basically with this setup I don't need to write a ROM every time I want to change something.

I know about AC and other logic types, I just haven't checked to see if the chips I need each have an AC variant, and I know that AC is also more susceptible to noise.

Thanks for the help, everyone. Honestly, I don't think I would have figured this out on my own.
Steve