Did anyone write an I2C interface using the CB2 and one data line of the 6522, using a "bit-bang" technque.
Rather than re-invent the wheel I was wondering if this was already done somewhere out there, and save me some learning effort.
many thanks
Mark
I2C Interface of a CB2, PB7
I2C Interface of a CB2, PB7
Last edited by diyhouse on Tue Nov 08, 2011 10:48 am, edited 1 time in total.
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
I use CB2 for the I²C clock on my workbench computer, and PB7 for the data. Using bit 7 for data works well for reading data because you can just branch on whether the byte is negative or not without ANDing-out a bit. You put a pull-up resistor on the port, set the output bit to always 0, then make the pin an input (with the data direction register) for reading data and an output only for pulling the line down. (Outputting a 1 is automatic if you leave the pin in input mode since the resistor pulls it up.)
I'm not using the pull-up on the clock line, but I will next time, not particularly for being able to have multiple controllers, but I understand that a few I²C devices hold the clock line down when they're not ready for more data. I have not encountered any such ICs yet, and I probably won't be going too fast by just bit-banging, and the I²C ICs I've used have software handshaking anyway with the ACK bit, reading a status register, etc..
If you do put the clock line on PA or PB, it works best to have it as bit 0, so you can put a positive pulse on the line for example with just INC DEC, just two instructions (assuming you have already set the bit low beforehand so you know you won't mess up the other bits).
I found my code for it but I'll have to do some translating into assembly since it's mosly in Forth. I can't take the time at the moment.
I'm not using the pull-up on the clock line, but I will next time, not particularly for being able to have multiple controllers, but I understand that a few I²C devices hold the clock line down when they're not ready for more data. I have not encountered any such ICs yet, and I probably won't be going too fast by just bit-banging, and the I²C ICs I've used have software handshaking anyway with the ACK bit, reading a status register, etc..
If you do put the clock line on PA or PB, it works best to have it as bit 0, so you can put a positive pulse on the line for example with just INC DEC, just two instructions (assuming you have already set the bit low beforehand so you know you won't mess up the other bits).
I found my code for it but I'll have to do some translating into assembly since it's mosly in Forth. I can't take the time at the moment.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
You and Daryl have email. Let me know if it came through correctly.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re:
diyhouse wrote:
Garth,.. Very great full,.. do you have an outlook as to when you might be able to do the conversion stuff,... I've got plenty of other things to do,.. I can just plan what to do next.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Re:
GARTHWILSON wrote:
...and I just posted working 65c02 assembly-language code to go with it, at http://wilsonminesco.com/6502primer/GENRLI2C.ASM. Hopefully I got all the special DOS/ANSI characters out of it (like ², µ, ±, etc.).
Note the 65C02 part. The code as written won't work with an NMOS MPU due to the use of TRB, TSB, etc.
As far as the DOS/ANSI characters go, I didn't see any, at least in the assembly language parts (I didn't peruse the Forth sections).
x86? We ain't got no x86. We don't NEED no stinking x86!
- GARTHWILSON
- Forum Moderator
- Posts: 8775
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: I2C Interface of a CB2, PB7
Yes, 65C02, which I strongly encourage in the primer since the reader is building new hardware. I wish the GUIs kept the DOS/ANSI [Edit: that should say IBM437] character set, because it is really nice for putting timing diagrams right in the source code, without .jpg's or anything that would make the assembler choke. Special characters too.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: I2C Interface of a CB2, PB7
GARTHWILSON wrote:
Yes, 65C02, which I strongly encourage in the primer since the reader is building new hardware. I wish the GUIs kept the DOS/ANSI character set, because it is really nice for putting timing diagrams right in the source code, without .jpg's or anything that would make the assembler choke. Special characters too.
The source code editor in the Kowalski simulator will accept the DOS/ANSI characters.
x86? We ain't got no x86. We don't NEED no stinking x86!