Page 1 of 1
I2CCmd
Posted: 04 September 2006, 19:01 PM
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.
Posted: 04 September 2006, 19:48 PM
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
I2CCmd
Posted: 05 September 2006, 15:11 PM
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
Posted: 05 September 2006, 15:20 PM
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.