|
|
| Author |
Message |
bodir
Joined: 05 Sep 2006
Posts: 3
|
|
Posted: 05 September 2006, 2:01 AM Post subject: I2CCmd |
|
|
| 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: |
|
|
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 |
|
|
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: |
|
|
| 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 |
|
 |
|