6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 3:16 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Nov 08, 2011 6:32 am 
Offline

Joined: Sun Jan 02, 2011 2:33 pm
Posts: 8
Location: UK
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


Last edited by diyhouse on Tue Nov 08, 2011 10:48 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 08, 2011 7:11 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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.

_________________
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?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 08, 2011 10:52 am 
Offline

Joined: Sun Jan 02, 2011 2:33 pm
Posts: 8
Location: UK
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 08, 2011 9:26 pm 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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?


Top
 Profile  
Reply with quote  
 Post subject: Re:
PostPosted: Wed Nov 14, 2012 7:28 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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.

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.).

_________________
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Re:
PostPosted: Wed Nov 14, 2012 4:29 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 14, 2012 8:01 pm 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
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?


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 17, 2012 7:00 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: