I2CCmd

Discussion specific to the DIP and TQFP packaged ZX devices like the ZX-40, ZX-44, ZX-32 and ZX-328 series. The differences between these devices is primarily the packaging and pinout so most issues will apply to all devices.
Post Reply
bodir
Posts: 3
Joined: 04 September 2006, 18:55 PM

I2CCmd

Post by bodir »

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.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

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: Select all

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
- Don Kinzer
bodir
Posts: 3
Joined: 04 September 2006, 18:55 PM

I2CCmd

Post by bodir »

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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

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.
- Don Kinzer
Post Reply