I2C¶
See the I2C Entity for generic information.
- class brainstem.entity.I2C(module, index)[source]¶
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.
- getSpeed()[source]¶
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
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valueunsigned char
The speed setting value.
- Return type:
- read(address, read_length)[source]¶
Read from a device on this I2C bus.
- Parameters:
address (unsigned char) – The I2C address (7bit <XXXX-XXX0>) of the device to read.
read_length (unsigned char) – The length of the data to read in bytes.
- Returns:
- Object containing error code and returned value on success.
- errorunsigned byte
An error result from the list of defined error codes
- valuelist(unsigned char)
The array of bytes that will be filled with the result, upon success. This array should be larger or equivalent to aBRAINSTEM_MAXPACKETBYTES - 5
- Return type:
- setPullup(enable)[source]¶
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:
enable (bool) – true enables pull-ups false disables them.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- setSpeed(speed)[source]¶
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 (unsigned char) – The speed setting value.
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte
- write(address, buffer)[source]¶
Write to a device on this I2C bus.
- Parameters:
address (unsigned char) – The I2C address (7bit <XXXX-XXX0>) of the device to write.
buffer (unsigned char) – The data to send to the device This array should be no larger than aBRAINSTEM_MAXPACKETBYTES - 5
- Returns:
An error result from the list of defined error codes in brainstem.result.Result
- Return type:
unsigned byte