This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
cubloc:set_i2c:index [2016/04/01 02:06] COMFILE Technology created |
cubloc:set_i2c:index [2021/09/13 08:42] (current) COMFILE Technology |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Set I2C ====== | ||
+ | ''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. | ||
+ | |||
+ | {{ :cubloc:set_i2c:seti2cv.png?nolink |}} | ||
+ | |||
+ | It may also help to add 100 Ohm damping resistors to the I2C lines, to dampen signal reflections or other sources of noise. | ||
+ | |||
+ | 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 | ||
+ | |||
+ | <code xbasic> | ||
+ | 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 | ||
+ | |||
+ | </code> | ||
+ | |||
+ | [[cubloc:index#system_library:|CUBLOC Home]] |