« Close

Datasheets and User Guides

App Notes

Software & Driver

 

25.1 I2C Library

Requires firmware 1.0224

The I2C library abstracts most of the Modbus calls needed to run I2C. The abstraction allows users to focus on I2C rather than Modbus, and reduces the memory requirements of scripts.

 

I2C.config

error = I2C.config(SDA, SCL, Speed, Options, Address)

Sets parameters that are not normally changed. Values set by this function will remain unchanged until this function is called again or the equivalent Modbus registers are written to.

Parameters:

  • SDA- DIO pin # that will be used as the I2C data line
  • SCL - DIO pin # that will be used as the I2C clock line
  • Speed    - See I2C documentation
  • Options - See I2C documentation
  • Address - Left Justified

Returns:

  • Error Code - standard LabJack T-Series error codes.

 

I2C.writeread

RxData, error = I2C.writeread(TxData, NumToRead)

This function will first write the data in TxData to the preset address, then will read NumToRead bytes from that same address.

Parameters:

  • TxData - This is a Lua table containing the values to be transmitted. The size of the table determines the number of bytes that will be transmitted.
  • NumToRead - The number of data bytes to be read.

Returns:

  • RxData - A Lua table of the values read
  • error - standard LabJack T-Series error codes.

 

I2C.read

RxData, error = I2C.read(NumToRead)

This function will read NumToRead bytes from the preset address.

Parameters:

  • NumToRead - The number of data bytes to be read.

Returns:

  • RxData - A Lua table of the values read
  • error - standard LabJack T-Series error codes.

 

I2C.write

error = I2C.write(TxData)

This function will write the data in TxData to the preset address.

Parameters:

  • TxData - This is a Lua table containing the values to be transmitted. The size of the table determines the number of bytes that will be transmitted.

Returns:

  • error - standard LabJack T-Series error codes.

 

I2C.search

AddressList, error = I2C.search(FirstAddress, LastAddress)

This function will scan the I2C bus addresses are acknowledged. An acknowledged address means that at least one device is set to that address. Addresses are tested sequentially between the first and last address parameters.

Parameters:

  • FirstAddress - The first address to be tested.
  • LastAddress - The last address to be tested.

Returns:

  • AddressList - A Lua table containing all the addresses that responded.
  • error - standard LabJack T-Series error codes.