PDA

View Full Version : Parameters in I2C


cbowen12345
11-11-2008, 04:36 PM
I am trying to read data from a I2C device. The following statement is made in the reference manual....


Parameter numToRead specifies how much data to read back from the external I2C device.



Is the "numToRead" an interger number? Assuming that is correct, is it the number of bits/bytes to be read?


Initially I am reading a status byte. Bits 0-6 contain information about how much of the80 byte receive buffer contains data and bit 7 is a flag indicating that the device buffer has data waiting.

Thanks for any assistance

Rick


PS. Writing to the device is not a problem

kbanks
11-12-2008, 08:31 AM
I am trying to read data from a I2C device. The following statement is made in the reference manual....

Parameter numToRead specifies how much data to read back from the external I2C device.

Is the "numToRead" an interger number? Assuming that is correct, is it the number of bits/bytes to be read?


Parameter numToRead is an integer, and specifies the number of bytes to read back.

You can see an example of this in file M41T81.py, which was installed along with Portal (look in your snappyImages directory).

If you look at routine readClock() in that file:


def readClock(firstReg, numRegs):
"""read a string of registers from the RTC"""
cmd = buildRtcCmd(firstReg, False)
i2cWrite(cmd, retries, False)

cmd = chr( RTC_ADDRESS | 1 )
result = i2cRead(cmd, numRegs, retries, False)

#dumpHex(result)
return result


...you can see that one byte is read back for every register.

The I2C examples i2cTests.py, M41T81.py, and CAT24C128.py are mentioned on page 35 of the 2.1 SNAP Reference Manual.

Take a look at those files to augment the documentation.