Page 1 of 1
I2C Interface of a CB2, PB7
Posted: Tue Nov 08, 2011 6:32 am
by diyhouse
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
Posted: Tue Nov 08, 2011 7:11 am
by GARTHWILSON
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.
Posted: Tue Nov 08, 2011 10:52 am
by diyhouse
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.
thanks
mark
Posted: Tue Nov 08, 2011 9:26 pm
by GARTHWILSON
You and Daryl have email. Let me know if it came through correctly.
Re:
Posted: Wed Nov 14, 2012 7:28 am
by GARTHWILSON
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.
There's an I²C interface in the "Interfacing to I²C" section of the potpourri page of my 6502 primer, 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 [Edit: that should say IBM437] characters out of it (like ², µ, ±, etc.).
Re: Re:
Posted: Wed Nov 14, 2012 4:29 pm
by BigDumbDinosaur
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).
Re: I2C Interface of a CB2, PB7
Posted: Wed Nov 14, 2012 8:01 pm
by GARTHWILSON
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.
Re: I2C Interface of a CB2, PB7
Posted: Sat Nov 17, 2012 7:00 pm
by BigDumbDinosaur
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.