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
PortI2C Class Reference

Can be used to drive a software (bit-banged) I2C bus via a Port interface. More...

#include <Ports.h>

Inheritance diagram for PortI2C:
Port HeadingBoard

Public Types

enum  { KHZMAX = 1, KHZ400 = 2, KHZ100 = 9 }
 

Public Member Functions

 PortI2C (uint8_t num, uint8_t rate=KHZMAX)
 Creates an instance of class PortI2C. More...
 
uint8_t start (uint8_t addr) const
 Initalize I2C communication on a JeeNode port. More...
 
void stop () const
 Terminate transmission on an I2C connection.
 
uint8_t write (uint8_t data) const
 Send one byte of data to the currently address I2C device. More...
 
uint8_t read (uint8_t last) const
 Read a byte using I2C protocol on a JeeNode port. More...
 
- Public Member Functions inherited from Port
 Port (uint8_t num)
 Contructor for a Port.
 
void mode (uint8_t value) const
 Set the pin mode of a Port's D pin. More...
 
uint8_t digiRead () const
 Reads the value of a Port's D pin. More...
 
void digiWrite (uint8_t value) const
 Write High or Low to a Port's D pin. More...
 
void anaWrite (uint8_t val) const
 Writes a PWM value to a Port's D pin.
 
uint32_t pulse (uint8_t state, uint32_t timeout=1000000L) const
 Applies the Arduino pulseIn() function on a Port's D pin. More...
 
void mode2 (uint8_t value) const
 Set the pin mode of a Port's A pin. More...
 
uint16_t anaRead () const
 Reads an analog value from a Port's A pin. More...
 
uint8_t digiRead2 () const
 Reads the value of a Port's A pin. More...
 
void digiWrite2 (uint8_t value) const
 Write High or Low to a Port's A pin. More...
 
uint32_t pulse2 (uint8_t state, uint32_t timeout=1000000L) const
 Applies the Arduino pulseIn() function on a Port's A pin. More...
 
void shift (uint8_t bitOrder, uint8_t value) const
 Does Arduino shiftOut() with data on D and clock on A pin of the Port. More...
 
uint16_t shiftRead (uint8_t bitOrder, uint8_t count=8) const
 Shift a number of bites in to read them. More...
 
void shiftWrite (uint8_t bitOrder, uint16_t value, uint8_t count=8) const
 The shiftWrite() call is similar but more general than the shift() call in that it allows an adjustable number of bits to be sent, not just 8. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Port
static void mode3 (uint8_t value)
 Set the pin mode of the I pin on all Ports. More...
 
static uint8_t digiRead3 ()
 Reads the value of the I pin on all Ports. More...
 
static void digiWrite3 (uint8_t value)
 Writes the value of the I pin on all Ports. More...
 
static void anaWrite3 (uint8_t val)
 Writes a PWM value to the I pin of all Ports.
 
- Protected Member Functions inherited from Port
uint8_t digiPin () const
 
uint8_t digiPin2 () const
 
uint8_t anaPin () const
 
- Static Protected Member Functions inherited from Port
static uint8_t digiPin3 ()
 
- Protected Attributes inherited from Port
uint8_t portNum
 The port number is a small integer mathing the hardware port used. More...
 

Detailed Description

Can be used to drive a software (bit-banged) I2C bus via a Port interface.

Todo:
Speed up the I2C bit I/O, it's far too slow right now.

The PortI2C class is a special version of class Port implementing the I2C / Two-Wire Interface (TWI) protocol. Allows using any port as I2C bus master. When used for I2C, DIO is used as SDA and AIO as SCL. Unlike the Wire library for the Arduino, which is a more advanced solution for the hardware I2C lines of an ATmega, the PortI2C class is implemented entirely in software using "bit-banging". Another difference is that PortI2C does not use interrupts and will keep the microcontroller occupied while it is performing I/O transfers.

See Also
DeviceI2C

Constructor & Destructor Documentation

PortI2C::PortI2C ( uint8_t  num,
uint8_t  rate = KHZMAX 
)

Creates an instance of class PortI2C.

Parameters
numport number corresponding to physical JeeNode port number.
ratein microseconds - time delay between bits? (not quite!)

Member Function Documentation

uint8_t PortI2C::read ( uint8_t  last) const

Read a byte using I2C protocol on a JeeNode port.

Parameters
lastpass 1 to signal the last byte read in this bus transaction
Returns
data (byte) read from the I2C device
uint8_t PortI2C::start ( uint8_t  addr) const

Initalize I2C communication on a JeeNode port.

Parameters
addrI2C address of device with which to communicate
Returns
1 if communication succeeded, 0 otherwise
uint8_t PortI2C::write ( uint8_t  data) const

Send one byte of data to the currently address I2C device.

Parameters
datathe data byte to send out
Returns
1 if device acknowledged write, 0 if device did not respond

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