I2C Entity

group I2CEntity

I2CClass. Interface the I2C buses on BrainStem modules. The class provides a way to send read and write commands to I2C devices on the entities bus.

void i2c_read(unsigned int *id, struct Result *result, const int index, const int address, const int bufferLength, unsigned char *buffer)

Read from a device on this I2C bus.

Parameters:
  • id – The id assigned by the create stem vi.

  • result – Object containing aErrNone on success. Non-zero error code on failure.

  • index – The index of the entity in question.

  • address – - The I2C address (7bit <XXXX-XXX0>) of the device to read.

  • length – - The length of the data to read in bytes.

  • result – - The array of bytes that will be filled with the result, upon success. This array should be larger or equivalent to aBRAINSTEM_MAXPACKETBYTES - 5

Returns:

Returns common entity return values

void i2c_write(unsigned int *id, struct Result *result, const int index, const int address, const int bufferLength, unsigned char *buffer)

Write to a device on this I2C bus.

Parameters:
  • id – The id assigned by the create stem vi.

  • result – Object containing aErrNone on success. Non-zero error code on failure.

  • index – The index of the entity in question.

  • address – - The I2C address (7bit <XXXX-XXX0>) of the device to write.

  • length – - The length of the data to write in bytes.

  • data – - The data to send to the device, This array should be no larger than aBRAINSTEM_MAXPACKETBYTES - 5

Returns:

Returns common entity return values

void i2c_setPullup(unsigned int *id, struct Result *result, const int index, const bool bEnable)

Set bus pull-up state. This call only works with stems that have software controlled pull-ups. Check the datasheet for more information. This parameter is saved when system.save is called.

Parameters:
  • id – The id assigned by the create stem vi.

  • result – Object containing aErrNone on success. Non-zero error code on failure.

  • index – The index of the entity in question.

  • bEnable – - true enables pull-ups false disables them.

Returns:

Returns common entity return values

void i2c_setSpeed(unsigned int *id, struct Result *result, const int index, const unsigned char speed)

Set I2C bus speed.

This call sets the communication speed for I2C transactions through this API. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz

Parameters:
  • id – The id assigned by the create stem vi.

  • result – Object containing aErrNone on success. Non-zero error code on failure.

  • index – The index of the entity in question.

  • speed – - The speed setting value.

Returns:

Returns common entity return values

void i2c_getSpeed(unsigned int *id, struct Result *result, const int index)

Get I2C bus speed.

This call gets the communication speed for I2C transactions through this API. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz

Parameters:
  • id – The id assigned by the create stem vi.

  • result – Object containing aErrNone and the requested value on success. Non-zero error code on failure.

  • index – The index of the entity in question.

Returns:

Returns common entity return values