I2C Class

class I2CClass

The I2CClass is the interface the I2C busses on BrainStem modules. The class provides a way to send read and write commands to I2C devices on the entitie’s bus.

Public Functions

I2CClass()

Constructor.

~I2CClass()

Destructor.

!I2CClass ()

Finalizer.

void init (BrainStem2CLI::ModuleClass^ module, const unsigned char index)

Initializes the class. Should only be called when manually creating classes.

Parameters:
  • pModule – The module.

  • index – The cmdI2C index to be addressed.

aErr read(const unsigned char address, const unsigned char length, unsigned char %result)

Read from a device on this I2C bus.

Parameters:
  • 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

aErr write(const unsigned char address, const unsigned char length, const unsigned char %data)

Write to a device on this I2C bus.

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

  • length – - The length of the data to read 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

aErr setPullup(const bool bEnable)

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

Parameters:

bEnable – - true enables pullups false disables them.

Returns:

Returns common entity return values

aErr setSpeed(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:

speed – - The speed setting value.

Returns:

Returns common entity return values

aErr getSpeed(unsigned char %speed)

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:

speed – - The speed setting value.

Returns:

Returns common entity return values