6522 VIA Serial mode - CB1 and CB2 pullup?

For discussing the 65xx hardware itself or electronics projects.
Post Reply
User avatar
AXY
Posts: 12
Joined: 11 Mar 2015

6522 VIA Serial mode - CB1 and CB2 pullup?

Post 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?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6522 VIA Serial mode - CB1 and CB2 pullup?

Post 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. [...]
Quote:

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.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
AXY
Posts: 12
Joined: 11 Mar 2015

Re: 6522 VIA Serial mode - CB1 and CB2 pullup?

Post 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!
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6522 VIA Serial mode - CB1 and CB2 pullup?

Post by GARTHWILSON »

I do empty the SR when setting it up. BIT SR is enough to do it.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
BigDumbDinosaur
Posts: 9427
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: 6522 VIA Serial mode - CB1 and CB2 pullup?

Post by BigDumbDinosaur »

Quote:

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
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
AXY
Posts: 12
Joined: 11 Mar 2015

Re: 6522 VIA Serial mode - CB1 and CB2 pullup?

Post 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.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6522 VIA Serial mode - CB1 and CB2 pullup?

Post 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 .
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Post Reply