I2CRead (Set up I2C Read)

The I2CRead instruction sets up the datalogger for reading in data via I2C communications.

NOTE: Campbell Scientific documentation has been updated to replace legacy industry terms with modern terminology. Controller-peripheral are now used to describe I2C communications. The I2C controller initiates communications and makes requests of peripheral device(s). Peripheral devices process requests and return an appropriate response.

Syntax

I2CRead ( BeginPort, Address, Dest, NumBytes, Option )

Remarks

I2C uses two bidirectional open-drain lines, the Serial Data Line (SDA) and Serial Clock Line (SCL) pulled up with resistors. The datalogger provides pull-ups to allow communications, but the pull resistors are not strong enough for high speed communications. If higher speeds are required, external pull-up resistors will be required.

Note that a prior understanding of the operation and details of the I2C protocol is assumed.

Parameters

BeginPort (Begin Port)

Specifies the beginning port used for the two signals for I2C communications. The first port is the clock signal and the next higher port is used for the data signal. Valid options are C1, C3, U1, U3, U5, U7, U9, and U11.

Type: Constant

Address (Address of I2C Peripheral)

The address of the I2C peripheral device. The read bit is appended to the address and should not be specified in the address.

Note: this is a 7-bit address. To represent the address correctly, rotate the bit pattern to the right by one bit. for example., an I2C address of &HB8 would be &H5C.

Type: Constant

Dest (Destination)

The variable in which to store the data read from the I2C device.

Type: Variable

NumBytes (Number of Bytes)

The number of bytes to read from/write to the I2C device.

Type: Variable or constant.

Option

A bit field parameter used to specify how the I2C transaction starts and ends.

Option Description
B0 Stop. Send a stop condition at the end of the transaction
B1 Start. Send a start condition at the beginning of the transaction. The address will be sent following the start.
B2

Restart. Send a restart condition at the beginning of the transaction. The address will be sent following the restart.

If Start or Restart are asserted the address will be sent prior to any data. If the stop is not set, it is assumed that another I2C instruction will occur, and the bus is left in control of the controller.

When all of the bytes are read and a stop is specified, the controller will send a NACK on the last byte. This is in accordance with the I2C specification and allows slave devices to reset their control state machines to a known state.

Examples of the “Option” parameter include:

Type: Constant