Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
I2CCmd

 
Post new topic   Reply to topic    Forum Index -> ZX-40
Author Message
bodir



Joined: 05 Sep 2006
Posts: 3

Posted: 05 September 2006, 2:01 AM    Post subject: I2CCmd Reply with quote

Can some one show me a snip of code for I2CCmd, I'm unable to make it work on my chip. Here's my chip ID ZX40 v1.3 004b,2796. I'm using 1.3 compiler also. Thanks.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 05 September 2006, 2:48 AM    Post subject: Reply with quote

The required code is device-dependent. Here is some simple code that works with the PCF8574A (taken from AN-203). It simply writes one byte and reads back a byte.

Code:
Private Const i2cChan as Byte = 0
Private Const i2cSpeed as Integer = 66
Private Const i2cAddr as Byte = &H70
Dim stat as Integer
Dim b as Byte

Sub Main()
   Call OpenI2C(i2cChan, 0, 0, i2cSpeed)
   b = &Hf5
   
   ' write the low nibble, read back the high nibble
   stat = I2CCmd(i2cChan, i2cAddr, 1, b, 1, b)
End Sub
Back to top
bodir



Joined: 05 Sep 2006
Posts: 3

Posted: 05 September 2006, 22:11 PM    Post subject: I2CCmd Reply with quote

After I declared this

Option Pin22 zxOutputHigh 'SCL I2C 10 pin con
Option Pin23 zxOutputHigh 'SDA I2C 10 pin con

it has started working. I haven't gotten any meaningful data yet but at least I can see data coming out of these pins with OScope now.

Thanks dkinzer
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 05 September 2006, 22:20 PM    Post subject: Reply with quote

You shouldn't need to set the pins high. The fact that it began working, after a fashion, when you did that suggests to me that the required pullup resistors might be missing. The I2C protocol requires a pullup on both SDA and SCL. A typical value to use is 2.2K but you might have to use lower values if your cable is long. The Atmel documentation gives equations to compute the pullup value range in terms of the supply voltage and bus capacitance. You can probably also find the equations in any other document that deals with the details of I2C.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-40 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group