Firmware-72 Command-125

From I-CubeX Wiki
Jump to: navigation, search

I2C PORT (125, 7Dh)

The USB-microDig can be used to communicate with I2C devices in both host and stand-alone modes of operation. Basically, I2C is a 2 wire communication bus allowing to transfer digital information between a master (herein the USB-microDig) and a slave (a sensor for example). General information about the I2C bus can easily be found on internet and is not intended to be described here. The implementation of the I2C bus on the USB-microDig uses an input pair of 2 adjacent inputs for its DATA (DA) and CLOCK (CK) lines.

Using the I2C PORT command you can check I2C port 0 to 6 and set it to input pair 1-2, 2-3, 3-4, 4-5, 5-6, 6 -7 or 7-8 respectively. It's not possible to use input pair 8-1 or 1-3 for example since they are not adjacent. The port number is set according to the distance from input pair 1-2 (pair 1-2 being port 0). For example, to set the port to input pair 7-8 you need to send the I2C PORT command with port number 6 (6th pair from input pair 1-2). The USB-microDig can have up to four I2C ports connected (side to side port 0, 2, 4 and 6).

The lowest number in an input pair (ex: 3 in pair 3-4) is connected to the data (DA) line and the highest input (ex: 4 in pair 3-4) is connected to the clock (CK) line. Both lines need to have a pull-up resistor connected to 5V (usually between 4.7K-10K Ohm) before the I2C PORT command can be sent to the USB-microDig. If no pull-up resistors are present (voltage not above 4V on DA and CK lines) the USB-microDig will respond to the I2C PORT command with a I2C PORT message indicating the port was not opened (F0h 7Dh 00h 7Dh xx F7h, where xx is the requested port). If the port has pull-up resistors then the USB-microDig will reply with the same message as the command. If no pull-up resistors are present on the I2C device, the USB-microDig’s internal pull-up resistors of 20K-50K Ohm can be enabled by setting the 6th bit in the port number byte of the I2C PORT command. Note that the value of the pull-up resistors in the USB-microDig may not be low enough for the I2C device to be recognized by the USB-microdig.

A port can have as many devices as there are different I2C addresses. Since a device only responds when its address is called the port could connect connect up to 128 I2C devices (address 00h to 7Fh). For the 4 available ports this would give a maximum of 128 x 4 = 512 devices ! The limit would however be the current consumption taken from the inputs (60mA max per port) of the USB-microDig.

The USB-microDig can only be used as an I2C master (ie. there is no I2C slave mode). The USB-microDig can both use analog sensors and communicate with I2C digital devices.The I2C clock speed is approximately 50kHz and cannot be changed. The I2C addressing is 7 bits only (no 10 bits address mode).

The I2C PORT command [BODY] is:

0xp00yyy: x = 1; enable port
x = 0; disable port
yyy = [0..6]; I2C port number, where port number = 0 corresponds with inputs 1-2
p = 1; enable internal pull-up resistors
p = 0; disable internal pull-up resistors

Examples:

This command attempts to open port 3 (inputs 4-5) for I2C communications:

240, 125, 0 {DEV}, 125 {I2C PORT}, 67 { x = 1, yyy = 3, p = 0}, 247 (F0h, 7Dh, 00h, 7Fh, 43h, F7h)

This command enables the internal pull-up resistors for port 3 (inputs 4-5) and then attempts to open port 3 for I2C communications:

240, 125, 0 {DEV}, 125 {I2C PORT}, 99 {x = 1, yyy = 3, p = 1}, 247 (F0h, 7Dh, 00h, 7Fh, 63h, F7h)