Set I2C dataPort, clockPort
|dataPort||SDA, data send/receive port. (0 to 255)|
|clockPort||SCL, clock send/receive port. (0 to 255)|
The Set I2C command sets the data port (SDA) and clock port (SCL), for I2C communication. Once this command is executed, both ports' I/O modes become output, and their outputs become logic high. For I2C communication please use ports capable of both input and output and 4.7K resistors as shown below.
I2C communication requires ports capable of both input and output, but some ports are only capable of either input or output. Please check the port specifications in the data sheet for the model you are using
Const Device = CB220 Dim adr As Integer Dim data As Byte Dim a As Byte data = &ha6 adr = &h3 Set I2C 7,6 Do I2CStart If I2CWrite(&b10100000)= 1 Then Goto err_proc a=I2CWrite(adr.byte1) a=I2CWrite(adr.lowbyte) a=I2CWrite(data) I2CStop Delay 1000 I2CStart a=I2CWrite(&b10100000) a=I2CWrite(adr.byte1) a=I2CWrite(adr.lowbyte) I2CStart a=I2CWrite(&b10100001) a=I2CRread(0) I2CStop Debug Hex a,cr ADR = ADR + 1 DATA = DATA + 1 Loop err_proc: Debug "Error !" Do Loop