WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
Public Member Functions | Friends | List of all members
I2C Class Reference

#include <I2C.h>

Inheritance diagram for I2C:
SensorBase

Public Member Functions

virtual ~I2C ()
 
bool Transaction (uint8_t *dataToSend, uint8_t sendSize, uint8_t *dataReceived, uint8_t receiveSize)
 
bool AddressOnly ()
 
bool Write (uint8_t registerAddress, uint8_t data)
 
bool Read (uint8_t registerAddress, uint8_t count, uint8_t *data)
 
void Broadcast (uint8_t registerAddress, uint8_t data)
 
void SetCompatibilityMode (bool enable)
 
bool VerifySensor (uint8_t registerAddress, uint8_t count, const uint8_t *expected)
 

Friends

class DigitalModule
 

Detailed Description

I2C bus interface class.

This class is intended to be used by sensor (and other I2C device) drivers. It probably should not be used directly.

It is constructed by calling DigitalModule::GetI2C() on a DigitalModule object.

Constructor & Destructor Documentation

I2C::~I2C ( )
virtual

Destructor.

Member Function Documentation

bool I2C::AddressOnly ( )

Attempt to address a device on the I2C bus.

This allows you to figure out if there is a device on the I2C bus that responds to the address specified in the constructor.

Returns
Transfer Aborted... false for success, true for aborted.
void I2C::Broadcast ( uint8_t  registerAddress,
uint8_t  data 
)

Send a broadcast write to all devices on the I2C bus.

This is not currently implemented!

Parameters
registerAddressThe register to write on all devices on the bus.
dataThe value to write to the devices.
bool I2C::Read ( uint8_t  registerAddress,
uint8_t  count,
uint8_t *  buffer 
)

Execute a read transaction with the device.

Read 1 to 7 bytes from a device. Most I2C devices will auto-increment the register pointer internally allowing you to read up to 7 consecutive registers on a device in a single transaction.

Parameters
registerAddressThe register to read first in the transaction.
countThe number of bytes to read in the transaction. [1..7]
bufferA pointer to the array of bytes to store the data read from the device.
Returns
Transfer Aborted... false for success, true for aborted.
void I2C::SetCompatibilityMode ( bool  enable)

SetCompatibilityMode

Enables bitwise clock skewing detection. This will reduce the I2C interface speed, but will allow you to communicate with devices that skew the clock at abnormal times. Compatability mode is enabled by default.

Parameters
enableEnable compatibility mode for this sensor or not.
bool I2C::Transaction ( uint8_t *  dataToSend,
uint8_t  sendSize,
uint8_t *  dataReceived,
uint8_t  receiveSize 
)

Generic transaction.

This is a lower-level interface to the I2C hardware giving you more control over each transaction.

Parameters
dataToSendBuffer of data to send as part of the transaction.
sendSizeNumber of bytes to send as part of the transaction. [0..6]
dataReceivedBuffer to read data into.
receiveSizeNumber of byted to read from the device. [0..7]
Returns
Transfer Aborted... false for success, true for aborted.
bool I2C::VerifySensor ( uint8_t  registerAddress,
uint8_t  count,
const uint8_t *  expected 
)

Verify that a device's registers contain expected values.

Most devices will have a set of registers that contain a known value that can be used to identify them. This allows an I2C device driver to easily verify that the device contains the expected value.

Precondition
The device must support and be configured to use register auto-increment.
Parameters
registerAddressThe base register to start reading from the device.
countThe size of the field to be verified.
expectedA buffer containing the values expected from the device.
bool I2C::Write ( uint8_t  registerAddress,
uint8_t  data 
)

Execute a write transaction with the device.

Write a single byte to a register on a device and wait until the transaction is complete.

Parameters
registerAddressThe address of the register on the device to be written.
dataThe byte to write to the register on the device.
Returns
Transfer Aborted... false for success, true for aborted.

The documentation for this class was generated from the following files: