Page 1 of 1
6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Wed Dec 23, 2015 10:55 pm
by AXY
Hey all, Happy Holidays to you all.
I'm trying to set up the 6522 for serial operation and I had a question about the CB1 and CB2 lines. It looks like the clock line is active low, but on reset, it looks like both CB1 and CB2 are low - is this normal?
Here's roughly my reset logic for the VIA:
Code: Select all
lda VIA0_IER
ora #VIA_IER_SR
sta VIA0_IER
lda VIA0_ACR
ora #%00001100 // ACR[4:2] = 011 - CB2 under external clock
sta VIA0_ACR
Am I missing some software steps or are there any electrical details that I missed? Do these lines need to be pulled up?
Re: 6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Thu Dec 24, 2015 12:01 am
by GARTHWILSON
From p.36 of the
data sheet:
- 3.9 Reset (RESB)
Reset clears all internal registers (except T1 and T2 counters and latches, and the SR. In the RESB
condition, all pins are placed in the input state and bus holding devices maintain initial level if not driven.
The initial level can be Logic 1 or Logic 0 and are not initialized by on chip circuitry. Also, T1 and T2, SR
and the interrupt logic are disabled from operation. [...]
Code: Select all
lda VIA0_ACR
ora #%00001100 // ACR[4:2] = 011 - CB2 under external clock
sta VIA0_ACR
To be sure you'll get mode 011 (particularly if you're setting it up after having used another mode since reset), you'll also need to AND-out bit 4 (since the ORA won't force it to a 0).
Unfortunately, SR mode 011 has the one and only bug in the VIA, all brands. I tell about it in tip #8 of the "Tip of the Day" column, at
viewtopic.php?p=2310#p2310 . See also the section "Using the 6522's shift register for tons of input bits"
http://wilsonminesco.com/6502primer/pot ... l#22_SR_IN in the "circuit potpourri" page of the 6502 primer.
You should generally activate the interrupt capability
after setting up whatever it is that will do the interrupting though.
Re: 6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Thu Dec 24, 2015 3:53 am
by AXY
Thanks Garth. I got my CB1/CB2 input problem solved - I miswired my DB15 connector that I'm using for Port B :-/.
Anyway, now that I've got the right inputs going into CB1/CB2 with the 7474 on the input clock, I couldn't get the 6522 to fire an interrupt. I was sure that I initialized everything. I guess by "except ... the SR" also means the internal shift counter, because you have to do one dummy load of SR to reset the counter on reset or no interrupts will ever occur, as far as I can tell. Grr!
Re: 6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Thu Dec 24, 2015 5:46 am
by GARTHWILSON
I do empty the SR when setting it up. BIT SR is enough to do it.
Re: 6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Thu Dec 24, 2015 7:04 am
by BigDumbDinosaur
Code: Select all
lda VIA0_ACR
ora #%00001100 // ACR[4:2] = 011 - CB2 under external clock
sta VIA0_ACR
If using a 65C02 or a 65C816, the above could be reduced to:
Code: Select all
LDA #%00001100 ;ACR[4:2] = 011 - CB2 under external clock
TSB VIA0_ACR
Re: 6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Sun Dec 27, 2015 8:43 pm
by AXY
Thanks to you both - I've now got my AVR-based PS/2 decoder talking to the serial lines of the 6522 and am displaying text on the screen! Cheers.
Re: 6522 VIA Serial mode - CB1 and CB2 pullup?
Posted: Sun Dec 27, 2015 8:51 pm
by GARTHWILSON
Doing raster graphics on an analog oscilloscope is one of the many things I've done with the VIA's SR. The circuit is pretty simple. See
viewtopic.php?p=2315#p2315 .