Skip to main content

I2cController Class

Namespace: GHIElectronics.TinyCLR.Devices.I2c · Assembly: GHIElectronics.TinyCLR.Devices.I2c

Represents an I²C bus controller. Open a peer with GetDevice(I2cConnectionSettings) to transact with a specific slave address. The same controller can serve multiple slaves — settings are re-applied per transfer.

public class I2cController : IDisposable

Properties

Provider

public II2cControllerProvider Provider { get; }

The low-level provider backing this controller.

Timeout

public TimeSpan Timeout { get; set; }

Maximum time the controller will block on a single transfer before giving up.

WriteBufferSize

public int WriteBufferSize { get; set; }

Slave-mode only: size in bytes of the controller's outgoing buffer.

ReadBufferSize

public int ReadBufferSize { get; set; }

Slave-mode only: size in bytes of the controller's incoming buffer.

BytesToWrite

public int BytesToWrite { get; }

Slave-mode only: bytes currently queued to transmit.

BytesToRead

public int BytesToRead { get; }

Slave-mode only: bytes currently available to read.

Methods

GetDefault()

public static I2cController GetDefault()

Returns the default I²C controller for this device.

Returns I2cController

FromName(string name)

public static I2cController FromName(string name)

Returns an I²C controller identified by its native API name.

ParameterTypeDescription
namestring

Returns I2cController

FromName(string name, GpioPin sdaPin, GpioPin sclPin)

public static I2cController FromName(string name, GpioPin sdaPin, GpioPin sclPin)

Returns a software (bit-bang) I²C controller using the supplied SDA/SCL pins.

ParameterTypeDescription
namestring
sdaPinGpioPin
sclPinGpioPin

Returns I2cController

FromName(string name, GpioPin sdaPin, GpioPin sclPin, bool usePullups)

public static I2cController FromName(string name, GpioPin sdaPin, GpioPin sclPin, bool usePullups)

Returns a software I²C controller, optionally engaging the internal pull-ups.

ParameterTypeDescription
namestringMust be the SoftwareI2cController native API name.
sdaPinGpioPinPin used as SDA.
sclPinGpioPinPin used as SCL.
usePullupsboolWhen true, configures SDA/SCL as inputs with internal pull-ups.

Returns I2cController

FromProvider(II2cControllerProvider provider)

public static I2cController FromProvider(II2cControllerProvider provider)

Creates a controller from a custom II2cControllerProvider.

ParameterTypeDescription
providerII2cControllerProvider

Returns I2cController

Dispose()

public void Dispose()

Releases the underlying provider.

GetDevice(I2cConnectionSettings connectionSettings)

public I2cDevice GetDevice(I2cConnectionSettings connectionSettings)

Creates an I2cDevice bound to this controller using the supplied settings.

ParameterTypeDescription
connectionSettingsI2cConnectionSettingsSlave address, bus speed, and master/slave mode.

Returns I2cDevice

ClearWriteBuffer()

public void ClearWriteBuffer()

Slave-mode only: empties the controller's outgoing buffer.

ClearReadBuffer()

public void ClearReadBuffer()

Slave-mode only: empties the controller's incoming buffer.