I2CCmd
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
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
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
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