Firmware-73 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. With the I2C PORT command you can check and enable/disable I2C port 0 to 7. The USB-microDig can have 8 I2C ports connected.

The implementation of the I2C bus on the USB-microDig uses the sensor input and actuator output of a single port for its DATA (SDA) and CLOCK (SCL) lines, by re-configuring the sensor input as SCL line and the actuator output as SDA line. I2C protocol requires that both lines have a pull-up resistor connected to 5V (usually between 4.7K-10K Ohm). if the I2C PORT command to enable the I2C port is sent to the USB-microDig and no (internal or external) pull-up resistors are present (voltage not above 4V on SDA and SCL 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 voltage on the lines to be pulled-up high enough and hence 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 8 available ports this would give a maximum of 128 x 8 = 1024 devices ! The limit would however be the current consumption taken from the inputs (30mA 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)