JeeLib
An easy interface to the port headers, the RF12 driver library, timers, low-power code, and more.
 All Classes Files Functions Variables Enumerations Macros Pages
DeviceI2C Class Reference

Each device on the I2C bus needs to be defined using a DeviceI2C instance. More...

#include <Ports.h>

Inheritance diagram for DeviceI2C:
AnalogPlug BMP085 ColorPlug CompassBoard DimmerPlug GravityPlug HYT131 LuxPlug MemoryPlug ProximityPlug

Public Member Functions

 DeviceI2C (const PortI2C &p, uint8_t me)
 
bool isPresent () const
 see if a device answers at an I2C address
 
uint8_t send () const
 Create a start condition on the I2C bus, and set things up for sending data to this device. More...
 
uint8_t receive () const
 Create a start condition on the I2C bus, and set things up for receiving data from this device. More...
 
void stop () const
 Create a stop condition on the I2C bus, ending the current transfer.
 
uint8_t write (uint8_t data) const
 Write a byte to the currently addressed device. More...
 
uint8_t read (uint8_t last) const
 Read a byte from the currently addressed device. More...
 
void setAddress (uint8_t me)
 

Detailed Description

Each device on the I2C bus needs to be defined using a DeviceI2C instance.

Since I2C is a bus, there are actually two classes involved. A PortI2C object manages a port as I2C master for one or more objects of class DeviceI2C, each representing a separate device. You can have multiple ports as I2C bus (running at a different speed perhaps), each talking to multiple I2C devices. Devices sharing the same bus must each have a unique ID in the range 0 .. 127.

See Also
PortI2C

Member Function Documentation

uint8_t DeviceI2C::read ( uint8_t  last) const
inline

Read a byte from the currently addressed device.

Must be preceded by a proper PortI2C start() call.

Parameters
lastIndicates whether this is the last byte to read. Used to respond to the write with a positive or negative ack. Pass 1 if reading the last byte, otherwise pass 0.
uint8_t DeviceI2C::receive ( ) const
inline

Create a start condition on the I2C bus, and set things up for receiving data from this device.

Returns
true if acknowledged.
uint8_t DeviceI2C::send ( ) const
inline

Create a start condition on the I2C bus, and set things up for sending data to this device.

Returns
true if acknowledged by the slave device.
uint8_t DeviceI2C::write ( uint8_t  data) const
inline

Write a byte to the currently addressed device.

Must be preceded by a proper PortI2C start() call.

Parameters
dataData byte to be sent.
Returns
true if the device acknowledged the byte (accepts more data).

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