Skip to main content

Class I2cBus

Represents an I2C communication channel that conforms to the ICommunicationBus contract.

Assembly: Meadow.F7.dll​
View Source​
Declaration
public class I2cBus : II2cBus, IDisposable

Implements:
Meadow.Hardware.II2cBus, System.IDisposable

Properties​

BusSpeed​

Bus Clock speed

View Source​
Declaration
public I2cBusSpeed BusSpeed { get; set; }

Methods​

From(IMeadowIOController, IPin, IPin, I2cBusSpeed, ushort)​

Creates an I2C bus for a set of given pins and parameters

View Source​
Declaration
public static I2cBus From(IMeadowIOController ioController, IPin clock, IPin data, I2cBusSpeed busSpeed, ushort transactionTimeout = 100)
Returns​

Meadow.Hardware.I2cBus: An I2CBus instance

Parameters​
TypeNameDescription
Meadow.Hardware.IMeadowIOControllerioControllerThe Meadow IO Controller
Meadow.Hardware.IPinclockClock (SCL) pin
Meadow.Hardware.IPindataData (SDA) pin
Meadow.Hardware.I2cBusSpeedbusSpeedI2C bus speed
System.UInt16transactionTimeoutBus transaction timeout

Read(byte, Span<byte>)​

Reads bytes from a peripheral

View Source​
Declaration
public void Read(byte peripheralAddress, Span<byte> readBuffer)
Parameters​
TypeNameDescription
System.ByteperipheralAddressThe I2C Address to read
System.Span<System.Byte>readBuffer

Write(byte, Span<byte>)​

Writes a number of bytes to the bus.

View Source​
Declaration
public void Write(byte peripheralAddress, Span<byte> data)
Parameters​
TypeNameDescription
System.ByteperipheralAddressAddress of the I2C peripheral.
System.Span<System.Byte>dataData to be written.

Exchange(byte, Span<byte>, Span<byte>)​

Writes data from the write buffer to a peripheral on the bus, then resets the bus and reads the return data into the read buffer.

View Source​
Declaration
public void Exchange(byte peripheralAddress, Span<byte> writeBuffer, Span<byte> readBuffer)
Parameters​
TypeNameDescription
System.ByteperipheralAddressAddress of the I2C peripheral.
System.Span<System.Byte>writeBufferBuffer to read data from.
System.Span<System.Byte>readBufferBuffer to read returning data into.

Dispose()​

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source​
Declaration
public void Dispose()

Implements​