Attention: this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.
I2C Library I2c uses system interrupt #18 The following flags can be set to act as interrupt sources: . More...
Enumerations |
|
enum | I2CSpeed { I2C_100KBPS, I2C_400KBPS, I2C_UNDEF_KBPS } |
Specification of possible i2c data rates. More... | |
Functions |
|
void | I2cIntGetLibVersion (DWORD *pVerMaj, DWORD *pVerMin, DWORD *pBuild) |
void | I2CGetLibVersion (DWORD *pVerMaj, DWORD *pVerMin, DWORD *pBuild) |
BOOL | GetI2CLock (DWORD timeout) |
BOOL | ReleaseI2CLock () |
BOOL | I2CInitEx (DWORD I2CRegAddr) |
BOOL | I2CInit (void) |
void | I2CDeInit (void) |
void | I2CSetSpeed (I2CSpeed Speed) |
BOOL | I2CBurstWrite (unsigned char uSlaveAddress, unsigned char *pBuffer, short ucOffset, unsigned iNumberBytes) |
BOOL | I2CBurstRead (unsigned char uSlaveAddress, unsigned char *pBuffer, short ucOffset, unsigned iNumberBytes) |
I2C Library
I2c uses system interrupt #18
The following flags can be set to act as interrupt sources:
.
#define I2C_OFFSET_NONE (-1) |
use this value in the I2CBurstRead/Write functions to avoid sending an offset byte
#define I2CLIB_VER_BUILD 0 |
Build Number of this library.
#define I2CLIB_VER_MAJ 4 |
Main Version of this library.
#define I2CLIB_VER_MIN 4 |
Subversion of this library.
enum I2CSpeed |
BOOL GetI2CLock | ( | DWORD | timeout | ) |
Syncronisation function if I2C bus is used in multiple threads (e.g. RTCSync which is loaded by default)
[in] | timeout | Maximum time [ms] to wait for the I2C Mutex |
TRUE | Success |
FALSE | See GetLastError(). possible Errors: WAIT_FAILED |
BOOL I2CBurstRead | ( | unsigned char | uSlaveAddress, |
unsigned char * | pBuffer, | ||
short | ucOffset, | ||
unsigned | iNumberBytes | ||
) |
Read data from one or multiple registers of an i2c device.
The function assumes that the i2c protocol defines the first transmitted byte to be the device's register offset.
[in] | uSlaveAddress | The device's i2c address (0..127) if uSlaveAddress=0xff, no slaveAddress byte will be transmitted. |
[in] | pBuffer | Pointer to the data bytes to Receive |
[in] | ucOffset | The device's register address (offset). This is one byte transmitted after the slave address. Set to any negative value if no offset byte should be transmitted |
[in] | iNumberBytes | Number of Bytes to Receive |
TRUE | success |
FALSE | Error during Transmission See GetLastError(). Possible error codes: ERROR_BUSY ERROR_INVALID_PARAMETER ERROR_TIMEOUT ERROR_IO_DEVICE ERROR_INVALID_ADDRESS ERROR_OPERATION_ABORTED |
BOOL I2CBurstWrite | ( | unsigned char | uSlaveAddress, |
unsigned char * | pBuffer, | ||
short | ucOffset, | ||
unsigned | iNumberBytes | ||
) |
Write data to one or multiple registers of an i2c device.
The function assumes that the i2c protocol defines the first transmitted byte to be the device's register offset.
[in] | uSlaveAddress | The device's i2c address (0..127) On Tegra T20 and T30 modules: if uSlaveAddress > 0x7f, then uSlaveAddress - 0x80 is used, and no stop bit is sent. |
[in] | pBuffer | Pointer to the data bytes to Transmit |
[in] | ucOffset | The device's register address (offset). This is one byte transmitted after the slave address. Set to any negative value if no offset byte should be transmitted |
[in] | iNumberBytes | Number of Bytes to Transmit |
TRUE | success |
FALSE | See GetLastError(). Possible error codes: ERROR_BUSY ERROR_INVALID_PARAMETER ERROR_TIMEOUT ERROR_IO_DEVICE ERROR_INVALID_ADDRESS ERROR_OPERATION_ABORTED On Tegra 3, a byte not acknowledged will be reported with a Timeout Error rather than an Operation Aborted Error |
void I2CDeInit | ( | void | ) |
DeInit I2C bus
Release I2C interrupt, unmap I2C registers and deinit Clock
void I2CGetLibVersion | ( | DWORD * | pVerMaj, |
DWORD * | pVerMin, | ||
DWORD * | pBuild | ||
) |
Returns the library Version - for compatibility
[out] | pVerMaj | Returns the major version number. Set this parameter to NULL if not required. |
[out] | pVerMin | Returns the minor version number. Set this parameter to NULL if not required. |
[out] | pBuild | Returns the build number. Set this parameter to NULL if not required. |
BOOL I2CInit | ( | void | ) |
Initialization to use I2C bus
Enable Clock, configure GPIOs, map registers, setup I2C interrupt
TRUE | success |
FALSE | See GetLastError(). Possible error codes: ERROR_INVALID_PARAMETER ERROR_NO_SYSTEM_RESOURCES ERROR_INVALID_COMPUTERNAME |
BOOL I2CInitEx | ( | DWORD | I2CRegAddr | ) |
Initialization to use I2C bus
Use this function instead of I2CInit() if you need to use another i2c bus than the default bus.
[in] | I2CRegAddr | Base address of the CPU's i2c controller. |
TRUE | Success |
FALSE | Unspecified Error. See GetLastError(). |
void I2cIntGetLibVersion | ( | DWORD * | pVerMaj, |
DWORD * | pVerMin, | ||
DWORD * | pBuild | ||
) |
Returns the library Version.
[out] | pVerMaj | Returns the major version number. Set this parameter to NULL if not required. |
[out] | pVerMin | Returns the minor version number. Set this parameter to NULL if not required. |
[out] | pBuild | Returns the build number. Set this parameter to NULL if not required. |
void I2CSetSpeed | ( | I2CSpeed | Speed | ) |
Set I2C bus speed.
Attention:
If the same i2c bus is used by multiple processes, the speed is preserved for each process individually. This is handled by the GetI2CLock() and ReleaseI2CLock() functions.
However if multiple threads within the same process use the same i2c bus, they all share a global speed setting.
[in] | Speed | I2C_100KBPS or I2C_400KBPS |
BOOL ReleaseI2CLock | ( | ) |
Release I2C bus for other threads (e.g. RTCSync which is loaded by default)
TRUE | Success |
FALSE | Unspecified Error. See GetLastError(). |