I2C Entity

group I2CEntity

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, int i2cNum, int address, int length, unsigned char *pData)

Read from a device on this I2C bus.

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

  • result: object, containing NO_ERROR or a non zero Error code.

  • i2cNum: The index of the I2C entity

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

  • length: The length of the data to read in bytes.

  • *pData: The array of bytes that will be filled with the result, upon success.

void i2c_write(unsigned int *id, struct Result *result, int i2cNum, int address, int length, unsigned char *pData)

Write to a device on this I2C bus.

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

  • result: object, containing NO_ERROR or a non zero Error code.

  • i2cNum: The index of the I2C entity

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

  • length: The length of the data to write in bytes.

  • *pData: The data to be written to the device

void i2c_setPullup(unsigned int *id, struct Result *result, int i2cNum, int enable)

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 NO_ERROR or a non zero Error code.

  • i2cNum: The index of the I2C entity

  • enable: 1 enables pull-ups; 0 disables them

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

Get I2C bus speed.

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

  • result: object, containing NO_ERROR and the speed of the I2C bus or a non zero Error code.

  • i2cNum: The index of the I2C entity

void i2c_setSpeed(unsigned int *id, struct Result *result, int i2cNum, int speed)

Set I2C bus speed.

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

  • result: object, containing NO_ERROR or a non zero Error code.

  • i2cNum: The index of the I2C entity

  • speed: The speed to be set. Speed is an enumeration value which can take the following values. 1 - 100Khz 2 - 400Khz 3 - 1MHz