U2C_RESULT U2C_CloseDevice( HANDLE hDevice );
The U2C_CloseDevice() function closes the open device handle.
Parameters:
Return values:
U2C_SUCCESS
The device referenced by hDevice handle was successfully closed.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_DropScl( HANDLE hDevice );
The U2C_DropScl() function pulls down the I2C bus SCL line.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
The SCL line was successfully dropped.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_DropSda( HANDLE hDevice );
The U2C_DropSda() function pulls down the I2C bus SDA line.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
The SDA line was successfully dropped.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetAck( HANDLE hDevice, );
The U2C_GetAck() function checks for acknowledge from I2C slave device. This function does not finish the I2C bus transaction after transmission, so at the end of I2C transaction U2C_Stop() function has to be called.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
I2C slave device provided acknowledge.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_NO_ACK
I2C slave device did not provide acknowledge.
U2C_RESULT U2C_GetByte( HANDLE hDevice, BYTE* pData );
The U2C_GetByte() function shifts in (reads) a single byte from I2C bus. It assumes that the bus is available, Start Condition has been previously generated and the slave device has been properly addressed. This function doesn't generate acknowledge, so you must call the U2C_PutAck() function or use U2C_GetByteWithAck() instead ofU2C_GetByte() function. This function can be called several times to implement custom I2C-like protocol. The function does not finish I2C bus transaction after transmission, so at the end of I2C transaction U2C_Stop() function has to be called.
Parameters:
Handle to the U2C-12 device.
A pointer to byte to be filled with data read from the I2C bus.
Return values:
U2C_SUCCESS
Byte was successfully read from I2C bus.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetByteWithAck( HANDLE hDevice, BYTE* pData, BOOL bAck );
The U2C_GetByteWithAck() function shifts in (reads) a single byte from the I2C bus and then generates acknowledge or not-acknowledge condition according to the value passed in bAck parameter. It assumes that the bus is available, Start Condition has been previously generated and the slave device has been properly addressed. This function can be called several times to implement custom I2C-like protocol. The function does not finish the I2C bus transaction after transmission, so at the end of I2C transaction U2C_Stop() function has to be called.
Parameters:
Handle to the U2C-12 device.
A pointer to byte to be filled with data read from the I2C bus.
This parameter determines if acknowledge should be generated after the byte is transmitted. If bAck is TRUE - acknowledge will be generated, if bAck is FALSE - non-acknowledge will be generated.
Return values:
U2C_SUCCESS
Byte was successfully read from I2C bus.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SetClockSynch( HANDLE hDevice, BOOL* pEnable );
The U2C_GetClockSynch() function retrieves I2C bus clock synchronization settings.
Clock synchronization (clock stretching) is used in situations where an I2C slave is not able to co-operate with the clock speed provided by the U2C-12 I2C master and needs to slow down the I2C bus. I2C slave holds down the SCL line low and in this way signals the I2C master about a wait state. If I2C bus clock synchronization is enabled, U2C-12 device will wait until I2C slave device releases the SCL line.
Warning | |
---|---|
I 2 C bus clock synchronization (clock stretching) is implemented for I 2 C bus frequencies up to 100kHz. See U2C_SetI2cFreq() to learn how to change I 2 C bus frequency. |
Parameters:
Handle to the U2C-12 device.
Clock synchronization (clock stretching) enable/disable value:
Return values:
U2C_SUCCESS
The I2C bus clock synchronization value was successfully retrieved.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetClockSynchTimeout( HANDLE hDevice, WORD* pTimeout );
The U2C_GetClockSynchTimeout() function retrieves timeout value for I2C bus clock synchronization.
Clock synchronization (clock stretching) is used in situations where I2C slave device is not able to cooperate on the clock speed provided by the U2C-12 I2C master and needs to slow down the I2C bus. I2C slave holds down the SCL line low and in that way signals the I2C master about a wait state. To avoid waiting deadlock (if some problem occurs with I2C slave device) timeout value was introduced into U2C-12 I2C interface. If I2C slave device doesn't release the clock within the given timeout interval, U2C-12 adapter returns the U2C_I2C_CLOCK_SYNCH_TIMEOUT error value.
Warning | |
---|---|
I 2 C bus clock synchronization (clock stretching) is implemented for I 2 C bus frequencies up to 100kHz. See U2C_SetI2cFreq() to learn how to change I 2 C bus frequency. |
Parameters:
Handle to the U2C-12 device.
Pointer to variable to be filled with clock synchronization timeout value.
Return values:
U2C_SUCCESS
The I2C bus clock synchronization timeout value was successfully retrieved.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
BYTE U2C_GetDeviceCount();
The U2C_GetDeviceCount() function checks how many U2C-12 devices are currently attached.
Returns:
The function returns the number of the U2C-12 devices detected on current computer.
U2C_VERSION_INFO U2C_GetDllVersion();
The U2C_GetDllVersion() function retrieves the version of the I2CBrdg.dll dynamic link library or shared library for Linux.
Returns:
U2C_VERSION_INFO structure containing I2CBrdg.dll dynamic link library version number.
U2C_RESULT U2C_GetDriverVersion( HANDLE hDevice, PU2C_VESION_INFO pVersion );
The U2C_GetDriverVersion() function retrieves the version of the driver used to communicate with U2C-12 device.
Parameters:
Return values:
U2C_SUCCESS
The driver version was successfully retrieved.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetFirmwareVersion( HANDLE hDevice, PU2C_VESION_INFO pVersion );
The U2C_GetFirmwareVersion() function retrieves the version of the firmware currently loaded into the U2C-12 device referenced by hDevice handle.
Parameters:
Return values:
U2C_SUCCESS
The firmware version was successfully retrieved.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetI2cFreq( HANDLE hDevice, BYTE* pFrequency );
The U2C_GetI2cFreq() function obtains I2C bus frequency.
Parameters:
Handle to the U2C-12 device.
A pointer to byte to be filled with current I2C bus frequency, where:
U2C_I2C_FREQ_FAST | I2C bus fast mode (400 kHz) |
U2C_I2C_FREQ_STD | I2C bus standard mode (100 kHz) |
U2C_I2C_FREQ_83KHZ | 83 kHz |
U2C_I2C_FREQ_71KHZ | 71 kHz |
U2C_I2C_FREQ_62KHZ | 62 kHz |
U2C_I2C_FREQ_50KHZ | 50 kHz |
U2C_I2C_FREQ_25KHZ | 25 kHz |
U2C_I2C_FREQ_10KHZ | 10 kHz |
U2C_I2C_FREQ_5KHZ | 5 kHz |
U2C_I2C_FREQ_2KHZ | 2 kHz |
Return values:
U2C_SUCCESS
The I2C bus frequency value was successfully retrieved.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetIoDirection( HANDLE hDevice, ULONG* pValue );
The U2C_GetIoDirection() function obtains current input/output direction of the GPIO port pins.
Parameters:
Handle to the U2C-12 device.
A pointer to unsigned long to be filled with the direction of the GPIO pins. pValue is treated as unsigned long 0xXXCCBBAA, where CC, BB and AA correspond to the C, B and A port pins:
Return values:
U2C_SUCCESS
The GPIO pins direction was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetSerialNum( HANDLE hDevice, long* pSerialNum );
The U2C_GetSerialNum() function retrieves the Serial Number of the current device. This is unique Serial Number. It can be used to identify device when you are using a number of U2C-12 devices simultaneously.
Parameters:
Return values:
U2C_SUCCESS
Serial Number was successfully obtained.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_GetSingleIoDirection( HANDLE hDevice, ULONG IoNumber, BOOL* pbOutput );
The U2C_GetSingleIoDirection() function obtains input/output direction of the specified GPIO pin.
Parameters:
Handle to the U2C-12 device.
The number of the GPIO pin to obtain direction:
A pointer to the boolean to be filled with the direction of the GPIO pin:
Return values:
U2C_SUCCESS
The GPIO pin direction was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
IoNumber is out of range.
U2C_RESULT U2C_IoRead( HANDLE hDevice, ULONG* pValue );
The U2C_IoRead() function obtains the value of the GPIO port pins.
Parameters:
Handle to the U2C-12 device.
A pointer to unsigned long to be filled with the value of the GPIO pins. pValue is treated as unsigned long 0xXXCCBBAA, where CC, BB and AA correspond to the C, B and A port pins:
Return values:
U2C_SUCCESS
The GPIO pins state was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_IoWrite( HANDLE hDevice, ULONG Value, ULONG Mask );
The U2C_IoWrite() sets the output value of the GPIO port pins. Pins have to be configured as output using the U2C_SetIoDirection() function first.
Parameters:
Handle to the U2C-12 device.
An unsigned long value specifying the value to be set to the GPIO pins. Value is treated as unsigned long 0xXXCCBBAA, where CC, BB and AA correspond to the C, B and A port pins:
An unsigned long value specifying the data mask to use when modifying the GPIO pins output value. The mask value allows modification of the desired pins only, leaving rest of the pins unchanged. The bit mapping for Mask parameter is exactly the same as for Value parameter. Only value of the pins with mask bit set to 1 will be changed.
Return values:
U2C_SUCCESS
The GPIO pins output value was successfully modified.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_IsHandleValid( HANDLE hDevice );
The U2C_IsHandleValid() function checks whether the device referenced by hDevice handle is currently attached to the USB and can be used by SW.
Parameters:
Return values:
U2C_SUCCESS
The device referenced by hDevice handle is present.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
HANDLE U2C_OpenDevice( BYTE nDevice );
The U2C_OpenDevice() function opens the U2C-12 device.
Parameters:
Returns:
If function succeeds, the return value is a valid handle to the specified device. If function fails, the return value is INVALID_HANDLE_VALUE. This can happen if the specified device is not present.
HANDLE U2C_OpenDeviceBySerialNum( long nSerialNum );
The U2C_OpenDeviceBySerialNum() function opens the U2C-12 device with specified Serial Number. This is unique Serial Number. It can be used to identify device when you are using a number of U2C-12 devices simultaneously.
Parameters:
Returns:
If function succeeds, the return value is a valid handle to the specified device. If function fails, the return value is INVALID_HANDLE_VALUE. This can happen if the device with specified Serial Number is not present.
U2C_RESULT U2C_PutAck( HANDLE hDevice, BOOL bAck );
The U2C_PutAck() function generates acknowledge or not-acknowledge condition according to the value passed in bAck parameter. This function does not finish the I2C bus transaction after transmission, so at the end of I2C transaction U2C_Stop() function has to be called.
Parameters:
Handle to the U2C-12 device.
This parameter determines whether acknowledge or non-acknowledge should be generated. If bAck is TRUE - acknowledge will be generated, if bAck is FALSE - non-acknowledge will be generated.
Return values:
U2C_SUCCESS
Acknowledge / non-acknowledge condition was successfully generated.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_PutByte( HANDLE hDevice, BYTE Data );
The U2C_PutByte() function shifts out (transmits) a single byte to I2C bus. It assumes that the bus is available and Start Condition has been generated first. This function doesn't check acknowledge from I2C slave device, so you must call the U2C_GetAck() function to check acknowledge or to use U2C_PutByteWithAck() instead ofU2C_PutByte() function. This function can be called several times to implement custom I2C-like protocol. The function does not finish I2C bus transaction after transmission, so at the end of I2C transaction U2C_Stop() function has to be called.
Parameters:
Handle to the U2C-12 device.
Byte value to be transmitted to the I2C bus.
Return values:
U2C_SUCCESS
Byte was successfully transmitted to the I2C bus.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_PutByteWithAck( HANDLE hDevice, BYTE Data );
The U2C_PutByteWithAck() function shifts out (transmits) a single byte to I2C bus and checks for acknowledge from I2C slave device. It assumes that the bus is available and Start Condition has been generated first. This function can be called several times to implement custom I2C-like protocol. The function does not finish the I2C bus transaction after transmission, so at the end of I2C transaction U2C_Stop() function has to be called.
Parameters:
Handle to the U2C-12 device.
Byte value to be transmitted to the I2C bus.
Return values:
U2C_SUCCESS
Byte was successfully transmitted to the I2C bus and I2C slave device provided acknowledge.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_NO_ACK
I2C slave device did not acknowledge the transmitted byte.
U2C_RESULT U2C_RW_Pack( HANDLE hDevice, PU2C_TRANSACTION_PACK pTransaction, int count );
Warning | |
---|---|
This function is implemented only for Linux and Mac versions of the library. |
The U2C_RW_Pack() function executes a list (pack) of I2C read/write transactions. All transactions are sent to U2C-12 device in a single USB transfer block.U2C_RW_Pack() waits until all I2C transactions are completed and returns each transaction result code in pTransaction[i].rc element. I2C transactions are performed sequentially in the same order as they are in the pack. Take care to pack correct sequence of the transactions. For instance attempt to read/write after write to I2C EEPROM may timeout because of the internal EEPROM write cycle.
Parameters:
Handle to the U2C-12 device.
List of I2C transactions.
Number of I2C transactions in the pTransaction list.
Return values:
U2C_SUCCESS
Operation was successfully completed and pList is filled with valid data.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
I2C transactions list is too big.
U2C_RESULT U2C_Read( HANDLE hDevice, PU2C_TRANSACTION pTransaction );
The U2C_Read function() reads up to 256 bytes from the I2C slave device.
Parameters:
Handle to the U2C-12 device.
Pointer to the U2C_TRANSACTION structure to be used during the I2C read transaction. Before calling the function this structure has to be partially filled:
Return values:
U2C_SUCCESS
The data was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_SLAVE_OPENNING_FOR_WRITE_FAILED
I2C slave device did not acknowledge write slave address.
U2C_SLAVE_OPENNING_FOR_READ_FAILED
I2C slave device did not acknowledge read slave address.
U2C_SENDING_MEMORY_ADDRESS_FAILED
I2C slave device did not acknowledge internal address.
U2C_RESULT U2C_ReadScl( HANDLE hDevice, U2C_LINE_STATE* pState );
The U2C_ReadScl() function checks the current state of the I2C bus SCL line.
Parameters:
Handle to the U2C-12 device.
Pointer to the location to be filled with the SCL line state:
Return values:
U2C_SUCCESS
The SCL line state was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_ReadSda( HANDLE hDevice, U2C_LINE_STATE* pState );
The U2C_ReadSda() function checks the current state of the I2C bus SDA line.
Parameters:
Handle to the U2C-12 device.
Pointer to the location to be filled with the SDA line state:
Return values:
U2C_SUCCESS
The SDA line state was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_ReleaseScl( HANDLE hDevice );
The U2C_ReleaseScl() function releases the SCL line of the I2C bus. If the SCL line is not pulled down by I2C slave device, it will get high.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
The SCL line was successfully released.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_ReleaseSda( HANDLE hDevice );
The U2C_ReleaseSda() function releases the SDA line of the I2C bus. If the line is not pulled down by I2C slave device, it will get high.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
The SDA line was successfully released.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_RepeatedStart( HANDLE hDevice );
The U2C_RepeatedStart() function generates repeated start condition on the I2C bus.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
Repeated start condition was successfully generated.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_ScanDevices( HANDLE hDevice, PU2C_SLAVE_ADDR_LIST pList );
The U2C_ScanDevices() function scans slave device addresses currently occupied by I2C slave devices connected to the I2C bus.
Parameters:
Handle to the U2C-12 device.
Pointer to the U2C_SLAVE_ADDR_LIST structure to be filled with slave device addresses. If function succeed nDeviceNumber member contains the number of the valid addresses in List array.
Return values:
U2C_SUCCESS
Operation was successfully completed and pList is filled with valid data.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SetClockSynch( HANDLE hDevice, BOOL Enable );
The U2C_SetClockSynch() function enables I2C bus clock synchronization.
Clock synchronization (clock stretching) is used in situations where an I2C slave is not able to co-operate with the clock speed provided by the U2C-12 I2C master and needs to slow down the I2C bus. I2C slave holds down the SCL line low and in this way signals the I2C master about a wait state. If I2C bus clock synchronization is enabled, U2C-12 device will wait until I2C slave device releases the SCL line.
Warning | |
---|---|
I 2 C bus clock synchronization (clock stretching) is implemented for I 2 C bus frequencies up to 100kHz. See U2C_SetI2cFreq() to learn how to change I 2 C bus frequency. |
Parameters:
Handle to the U2C-12 device.
Clock synchronization (clock stretching) enable/disable value:
Return values:
U2C_SUCCESS
The I2C bus clock synchronization value was successfully set.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SetClockSynchTimeout( HANDLE hDevice, WORD Timeout );
The U2C_SetClockSynchTimeout() function configures timeout value for I2C bus clock synchronization.
Clock synchronization (clock stretching) is used in situations where I2C slave device is not able to cooperate on the clock speed provided by the U2C-12 I2C master and needs to slow down the I2C bus. I2C slave holds down the SCL line low and in that way signals the I2C master about a wait state. To avoid waiting deadlock (if some problem occurs with I2C slave device) timeout value was introduced into U2C-12 I2C interface. If I2C slave device doesn't release the clock within the given timeout interval, U2C-12 adapter returns the U2C_I2C_CLOCK_SYNCH_TIMEOUT error value.
The U2C_SetClockSynchTimeout() function doesn't enables or disables clock stretching functionality. It only changes the clock stretching timeout value. Clock stretching should be enabled with U2C_SetClockSynch() function.
Warning | |
---|---|
I 2 C bus clock synchronization (clock stretching) is implemented for I 2 C bus frequencies up to 100kHz. See U2C_SetI2cFreq() to learn how to change I 2 C bus frequency. |
Parameters:
Handle to the U2C-12 device.
Clock synchronization (clock stretching) timeout value specified as multiple of 100 microseconds.
Return values:
U2C_SUCCESS
The I2C bus clock synchronization timeout value was successfully set.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SetI2cFreq( HANDLE hDevice, BYTE Frequency );
The U2C_SetI2cFreq() function configures I2C bus frequency.
Parameters:
Handle to the U2C-12 device.
The frequency of I2C bus, where:
U2C_I2C_FREQ_FAST | I2C bus fast mode (400 kHz) |
U2C_I2C_FREQ_STD | I2C bus standard mode (100 kHz) |
U2C_I2C_FREQ_83KHZ | 83 kHz |
U2C_I2C_FREQ_71KHZ | 71 kHz |
U2C_I2C_FREQ_62KHZ | 62 kHz |
U2C_I2C_FREQ_50KHZ | 50 kHz |
U2C_I2C_FREQ_25KHZ | 25 kHz |
U2C_I2C_FREQ_10KHZ | 10 kHz |
U2C_I2C_FREQ_5KHZ | 5 kHz |
U2C_I2C_FREQ_2KHZ | 2 kHz |
Return values:
U2C_SUCCESS
The I2C bus frequency value was successfully set.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SetIoDirection( HANDLE hDevice, ULONG Value, ULONG Mask );
The U2C_SetIoDirection() function configures input/output direction of the GPIO port pins.
Parameters:
Handle to the U2C-12 device.
An unsigned long value specifying the direction of the GPIO pins. Value is treated as unsigned long 0xXXCCBBAA, where CC, BB and AA correspond to the C, B and A port pins:
An unsigned long value specifying the data mask to use when modifying the GPIO pins direction. The mask value allows modification of the desired pins only, leaving rest of the pins unchanged. The bit mapping for Mask parameter is exactly the same as for Value parameter. Only direction of the pins with the mask bit set to 1 will be changed.
Return values:
U2C_SUCCESS
The GPIO pins direction was successfully modified.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SetSingleIoDirection( HANDLE hDevice, ULONG IoNumber, BOOL bOutput );
The U2C_SetSingleIoDirection() function configures input/output direction of the specified GPIO pin.
Parameters:
Handle to the U2C-12 device.
The number of the GPIO pin to change direction:
The direction of the GPIO pin:
Return values:
U2C_SUCCESS
The GPIO pin direction was successfully modified.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
IoNumber is out of range.
U2C_RESULT U2C_SingleIoRead( HANDLE hDevice, ULONG IoNumber, BOOL* pValue );
The U2C_SingleIoRead() function obtains the value of the specified GPIO pin.
Parameters:
Handle to the U2C-12 device.
The number of the GPIO pin to obtain value from:
A pointer to boolean to be filled with the GPIO pin state.
Return values:
U2C_SUCCESS
The GPIO pin state was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
IoNumber is out of range.
U2C_RESULT U2C_SingleIoWrite( HANDLE hDevice, ULONG IoNumber, BOOL Value );
The U2C_SingleIoWrite() function sets the output value of the specified GPIO pin. Pin must be configured as output using U2C_SetIoDirection() orU2C_SetSingleIoDirection() functions first.
Parameters:
Handle to the U2C-12 device.
The number of the GPIO pin to set output value to:
The GPIO pin new output value.
Return values:
U2C_SUCCESS
The GPIO pin output value was successfully modified.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
IoNumber is out of range.
U2C_RESULT U2C_SpiConfigSS( HANDLE hDevice, ULONG IoNumber, BOOL ActiveHigh );
The U2C_SpiConfigSS() function configures GPIO pin specified by IoNumber as SPI Bus Slave Select (Master Select) signal.
To benefit from Slave Select signal during SPI communication you should use Slave Select aware functions set:
Slave Select pin remains unchanged if you call U2C_SpiReadWrite(), U2C_SpiWrite() or U2C_SpiRead() function. This can be useful if you want to send or receive several buffers through SPI Bus changing Slave Select pin only once. You can use GPIO routines to work with Slave Select signal in such a case.
You can configure any number of pins for Slave Select signal and specify different pins for each SPI transaction.
Parameters:
Handle to the U2C-12 device.
GPIO pin to be configured as Slave Select (Master Select) signal.
This parameter determines the active state of the Slave Select signal (state during the SPI transfer). If ActiveHigh is TRUE - Slave Select pin value will be changed from logical "0" to logical "1" before SPI transaction and returned back to logical "0" after the data is transmitted. If ActiveHigh is FALSE - Slave Select pin value will be changed from logical "1" to logical "0" before SPI transaction and returned back to logical "1" after the data is transmitted.
Return values:
U2C_SUCCESS
The Slave Select pin was successfully configured.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
IoNumber is out of range.
U2C_RESULT U2C_SpiGetConfig( HANDLE hDevice, BYTE* pCPOL, BYTE* pCPHA );
The U2C_SpiGetConfig() function obtains SPI bus configuration (clock polarity and phase).
Parameters:
Handle to the U2C-12 device.
A pointer to the byte to be filled with current SPI bus clock polarity setting. Clock polarity determines the CLK line idle state, where:
A pointer to byte to be filled with current SPI bus clock phase setting. Clock phase value determines the clock edge when the data is valid on the bus, where:
Return values:
U2C_SUCCESS
The SPI bus configuration was successfully obtained.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SpiGetConfigEx( HANDLE hDevice, DWORD* pConfig );
The U2C_SpiGetConfigEx() function obtains SPI configuration.
Parameters:
Handle to the U2C-12 device.
A pointer to DWORD to be filled with current SPI configuration:
Return values:
U2C_SUCCESS
The SPI bus configuration was successfully obtained.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SpiGetFreq( HANDLE hDevice, BYTE* pFrequency );
The U2C_SpiGetFreq() function obtains SPI bus frequency.
Parameters:
Handle to the U2C-12 device.
A pointer to byte to be filled with the current SPI bus frequency, where:
U2C_SPI_FREQ_200KHZ | 200 kHz |
U2C_SPI_FREQ_100KHZ | 100 kHz |
U2C_SPI_FREQ_83KHZ | 83 kHz |
U2C_SPI_FREQ_71KHZ | 71 kHz |
U2C_SPI_FREQ_62KHZ | 62 kHz |
U2C_SPI_FREQ_50KHZ | 50 kHz |
U2C_SPI_FREQ_25KHZ | 25 kHz |
U2C_SPI_FREQ_10KHZ | 10 kHz |
U2C_SPI_FREQ_5KHZ | 5 kHz |
U2C_SPI_FREQ_2KHZ | 2 kHz |
Return values:
U2C_SUCCESS
The SPI bus frequency value was successfully retrieved.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SpiRead( HANDLE hDevice, BYTE* pInBuffer, unsigned short Length );
The U2C_SpiRead() function shifts in (reads) a stream of up to 256 bytes from the SPI slave device.
Parameters:
Handle to the U2C-12 device.
Pointer to the buffer that receives the data shifted in from the SPI slave device.
Number of bytes to be shifted in. Maximum value is 256.
Return values:
U2C_SUCCESS
The data was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
Length parameter is out of range.
U2C_RESULT U2C_SpiReadSS( HANDLE hDevice, BYTE* pInBuffer, WORD Length ULONG IoNumber BOOL ActiveHigh );
The U2C_SpiReadSS() function shifts in (reads) a stream of up to 256 bytes from the SPI slave device.
In contrast to U2C_SpiRead() function, U2C_SpiReadSS() also selects the SPI slave device to communicate with. Slave Select pin should be preconfigured withU2C_SpiConfigSS() function. You can configure any number of pins for Slave Select signal and specify different pins for each SPI transaction.
Use U2C_SpiRead() function if you don't want to involve slave device selection into SPI transaction. This can be useful if you want to receive several buffers through SPI Bus changing Slave Select pin only once. You can use GPIO routines to work with Slave Select pin in such a case.
Parameters:
Handle to the U2C-12 device.
Pointer to the buffer that receives the data shifted in from the SPI slave device.
Number of bytes to be shifted in. Maximum value is 256.
GPIO pin to be used for SPI slave device selection.
This parameter determines the active state of the Slave Select pin (state during the SPI transfer). If ActiveHigh is TRUE - Slave Select pin value will be changed from logical "0" to logical "1" before SPI transaction and returned back to logical "0" after the data is transmitted. If ActiveHigh is FALSE - Slave Select pin value will be changed from logical "1" to logical "0" before SPI transaction and returned back to logical "1" after the data is transmitted.
Return values:
U2C_SUCCESS
The data was successfully read.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
Length or IoNumber parameter is out of range.
U2C_RESULT U2C_SpiReadWrite( HANDLE hDevice, BYTE* pOutBuffer, BYTE* pInBuffer, unsigned short Length );
The U2C_SpiReadWrite() function shifts out (writes) and in (reads) a stream of up to 256 bytes to/from the SPI slave device.
Parameters:
Handle to the U2C-12 device.
Pointer to the buffer containing the data to be shifted out to the SPI slave device.
Pointer to the buffer that receives the data shifted in from the SPI slave device.
Number of bytes to be transferred via SPI bus. Maximum value is 256.
Return values:
U2C_SUCCESS
The data was successfully transmitted via SPI bus.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
Length parameter is out of range.
U2C_RESULT U2C_SpiReadWriteSS( HANDLE hDevice, BYTE* pOutBuffer, BYTE* pInBuffer, WORD Length ULONG IoNumber BOOL ActiveHigh );
The U2C_SpiReadWriteSS() function shifts out (writes) and in (reads) a stream of up to 256 bytes to/from the SPI slave device.
In contrast to U2C_SpiReadWrite() function, U2C_SpiReadWriteSS() also selects the SPI slave device to communicate with. Slave Select pin should be preconfigured withU2C_SpiConfigSS() function. You can configure any number of pins for Slave Select signal and specify different pins for each SPI transaction.
Use U2C_SpiReadWrite() function if you don't want to involve slave device selection into SPI transaction. This can be useful if you want to send or receive several buffers through SPI Bus changing Slave Select pin only once. You can use GPIO routines to work with Slave Select pin in such a case.
Parameters:
Handle to the U2C-12 device.
Pointer to the buffer containing the data to be shifted out to the SPI slave device.
Pointer to the buffer that receives the data shifted in from the SPI slave device.
Number of bytes to be transferred via SPI bus. Maximum value is 256.
GPIO pin to be used for SPI slave device selection.
This parameter determines the active state of the Slave Select pin (state during the SPI transfer). If ActiveHigh is TRUE - Slave Select pin value will be changed from logical "0" to logical "1" before SPI transaction and returned back to logical "0" after the data is transmitted. If ActiveHigh is FALSE - Slave Select pin value will be changed from logical "1" to logical "0" before SPI transaction and returned back to logical "1" after the data is transmitted.
Return values:
U2C_SUCCESS
The data was successfully transmitted via SPI bus.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
Length or IoNumber parameter is out of range.
U2C_RESULT U2C_SpiSetConfig( HANDLE hDevice, BYTE CPOL, BYTE CPHA );
The U2C_SpiSetConfig() function configures SPI bus clock polarity and phase.
Parameters:
Handle to the U2C-12 device.
Clock polarity value determines the CLK line idle state, where:
Clock phase value determines the clock edge when the data is valid on the bus, where:
Return values:
U2C_SUCCESS
The SPI bus was successfully configured.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SpiSetConfigEx( HANDLE hDevice, DWORD Config );
The U2C_SpiSetConfigEx() function enables/disables and configures SPI interface.
Parameters:
Handle to the U2C-12 device.
SPI configuration bits:
Return values:
U2C_SUCCESS
SPI bus was successfully configured.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SpiSetFreq( HANDLE hDevice, BYTE Frequency );
The U2C_SpiSetFreq() function configures SPI bus frequency.
Parameters:
Handle to the U2C-12 device.
The frequency of SPI bus, where:
U2C_SPI_FREQ_200KHZ | 200 kHz |
U2C_SPI_FREQ_100KHZ | 100 kHz |
U2C_SPI_FREQ_83KHZ | 83 kHz |
U2C_SPI_FREQ_71KHZ | 71 kHz |
U2C_SPI_FREQ_62KHZ | 62 kHz |
U2C_SPI_FREQ_50KHZ | 50 kHz |
U2C_SPI_FREQ_25KHZ | 25 kHz |
U2C_SPI_FREQ_10KHZ | 10 kHz |
U2C_SPI_FREQ_5KHZ | 5 kHz |
U2C_SPI_FREQ_2KHZ | 2 kHz |
Return values:
U2C_SUCCESS
The SPI bus frequency value was successfully set.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_SpiWrite( HANDLE hDevice, BYTE* pOutBuffer, unsigned short Length );
The U2C_SpiWrite() function shifts out (writes) a stream of up to 256 bytes to the SPI slave device.
Parameters:
Handle to the U2C-12 device.
Pointer to the buffer containing the data to be shifted out to the SPI slave device.
Number of bytes to be shifted out to the SPI slave device. Maximum value is 256.
Return values:
U2C_SUCCESS
The data was successfully written to the SPI slave device.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
Length parameter is out of range.
U2C_RESULT U2C_SpiWriteSS( HANDLE hDevice, BYTE* pOutBuffer, WORD Length ULONG IoNumber BOOL ActiveHigh );
The U2C_SpiWriteSS() function shifts out (writes) a stream of up to 256 bytes to the SPI slave device.
In contrast to U2C_SpiWrite() function, U2C_SpiWriteSS() also selects the SPI slave device to communicate with. Slave Select pin should be preconfigured withU2C_SpiConfigSS() function. You can configure any number of pins for Slave Select signal and specify different pins for each SPI transaction.
Use U2C_SpiWrite() function if you don't want to involve slave device selection into SPI transaction. This can be useful if you want to send several buffers through SPI Bus changing Slave Select pin only once. You can use GPIO routines to work with Slave Select pin in such a case.
Parameters:
Handle to the U2C-12 device.
Pointer to the buffer containing the data to be shifted out to the SPI slave device.
Number of bytes to be shifted out to the SPI slave device. Maximum value is 256.
GPIO pin to be used for SPI slave device selection.
This parameter determines the active state of the Slave Select pin (state during the SPI transfer). If ActiveHigh is TRUE - Slave Select pin value will be changed from logical "0" to logical "1" before SPI transaction and returned back to logical "0" after the data is transmitted. If ActiveHigh is FALSE - Slave Select pin value will be changed from logical "1" to logical "0" before SPI transaction and returned back to logical "1" after the data is transmitted.
Return values:
U2C_SUCCESS
The data was successfully written to the SPI slave device.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_BAD_PARAMETER
Length or IoNumber parameter is out of range.
U2C_RESULT U2C_Start( HANDLE hDevice );
The U2C_Start() function generates start condition on the I2C bus.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
Start condition was successfully generated.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_Stop( HANDLE hDevice );
The U2C_Stop() function generates stop condition on I2C bus. You can also use this function to generate repeated stop condition.
Parameters:
Handle to the U2C-12 device.
Return values:
U2C_SUCCESS
Stop condition was successfully generated.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_RESULT U2C_Write( HANDLE hDevice, PU2C_TRANSACTION pTransaction );
The U2C_Write() function writes up to 256 bytes into the I2C slave device.
Parameters:
Handle to the U2C-12 device.
Pointer to the U2C_TRANSACTION structure to be used during the I2C write transaction. Before calling the function this structure have to be filled:
Return values:
U2C_SUCCESS
The data was successfully written into the I2C slave device.
U2C_HARDWARE_NOT_FOUND
U2C-12 device referenced by hDevice handle was not found.
U2C_SLAVE_OPENNING_FOR_WRITE_FAILED
I2C slave device did not acknowledge write slave address.
U2C_SENDING_MEMORY_ADDRESS_FAILED
I2C slave device did not acknowledge internal address.
U2C_SENDING_DATA_FAILED
I2C slave did not acknowledge data output.