Firmware-72 Command-127

From I-CubeX Wiki
Jump to: navigation, search

I2C READ (127, 7Fh)

The I2C READ command can be used to transfer data from a I2C device. Unless the I2C device has no pull-up resistors it is not necessary to use the I2C PORT command before sending the I2C READ command. The command can be used in both host and stand-alone modes of operation.

The I2C READ command [BODY] is:

00000xxx: xxx = [0..6]; I2C port number
0aaaaaaa: aaaaaa = [0..127]; I2C address of device
0000bbbb:
0000cccc: bbbbcccc = [0..255]; register number of device
0ddddddd: ddddddd = [1..127]; number of bytes to read

Example:

240, 125, 0 {DEV}, 127 {I2C READ}, 4 {port number}, 56 {address of device}, 0, 0 {register 0 = 0*16+0}, 2 {number of bytes to read 2}, 247 (F0h, 7Dh, 00h, 7Fh, 04h, 38h, 00h, 00h, 01h, F7h)

If the device responded to the provided I2C address “aaaaaaa” (I2C devices always acknowledge when it’s address is called) then the USB-microDig will respond with an I2C READ message message having the same address, the same register number followed by the number of bytes that was requested and the data bytes (according to the example above, the reply message could be: F0h, 7Dh, 00h, 7Fh, 04h, 38h, 00h, 00h, 02h, 0Ah, 0Bh, 04h, 07h, F7h thus the received bytes would be ABh and 47h). Each requested byte is split as two consecutive bytes having their upper 4 bits to zero and encoded as upper byte sent first then lower byte (ex. 47h would be sent as 04h 07h). If there was no acknowledgement from the device within 100 ms (eg. wrong address or device not present) then the USB-microDig will respond with an I2C NO RESPONSE message (ie. in the above case the response would be F0h, 00h, 7Bh, 04h, 38h, F7h). If the I2C port on the USB-microDig was not opened the USB-microDig will respond with an I2C PORT message indicating the port was not opened (F0h 7Dh 00h 7Dh 04h F7h, where the port number is 4).