Digital IO
Classes | Functions | Variables
Software I2C

Classes

class  FastI2cMaster< sclPin, sdaPin >
 AVR Fast software I2C master class. More...
 
class  I2cMasterBase
 Base class for FastI2cMaster, SoftI2cMaster. More...
 
class  SoftI2cMaster
 AVR Software I2C master class. More...
 

Functions

 SoftI2cMaster::SoftI2cMaster (uint8_t sclPin, uint8_t sdaPin)
 
void SoftI2cMaster::begin (uint8_t sclPin, uint8_t sdaPin)
 
uint8_t SoftI2cMaster::read (uint8_t last)
 
void SoftI2cMaster::start ()
 
void SoftI2cMaster::stop (void)
 
bool I2cMasterBase::transfer (uint8_t addressRW, void *buf, size_t nbyte, uint8_t option=I2C_STOP)
 
bool I2cMasterBase::transferContinue (void *buf, size_t nbyte, uint8_t option=I2C_STOP)
 
bool SoftI2cMaster::write (uint8_t b)
 

Variables

const uint8_t STATE_REP_START = 1
 
const uint8_t STATE_RX_ADDR_NACK = 4
 
const uint8_t STATE_RX_DATA = 2
 
const uint8_t STATE_STOP = 0
 
const uint8_t STATE_TX_ADDR_NACK = 5
 
const uint8_t STATE_TX_DATA = 3
 
const uint8_t STATE_TX_DATA_NACK = 6
 

Detailed Description

Software Two Wire Interface library.

Function Documentation

SoftI2cMaster::SoftI2cMaster ( uint8_t  sclPin,
uint8_t  sdaPin 
)

Constructor, initialize SCL/SDA pins and set the bus high.

Parameters
[in]sdaPinThe software SDA pin number.
[in]sclPinThe software SCL pin number.

Definition at line 115 of file SoftI2cMaster.cpp.

void SoftI2cMaster::begin ( uint8_t  sclPin,
uint8_t  sdaPin 
)

Initialize SCL/SDA pins and set the bus high.

Parameters
[in]sdaPinThe software SDA pin number.
[in]sclPinThe software SCL pin number.

Definition at line 126 of file SoftI2cMaster.cpp.

uint8_t SoftI2cMaster::read ( uint8_t  last)
virtual

Read a byte

Note
This function should only be used by experts. Data should be accessed by calling transfer() and transferContinue()
Parameters
[in]lastsend a NACK to terminate read if last is true else send an ACK to continue the read.
Returns
byte read from I2C bus

Implements I2cMasterBase.

Definition at line 160 of file SoftI2cMaster.cpp.

void SoftI2cMaster::start ( )
virtual

Issue a start condition

Note
This function should only be used by experts. Data should be accessed by calling transfer() and transferContinue()

Implements I2cMasterBase.

Definition at line 186 of file SoftI2cMaster.cpp.

void SoftI2cMaster::stop ( void  )
virtual

Issue a stop condition.

Note
This function should only be used by experts. Data should be accessed by calling transfer() and transferContinue()

Implements I2cMasterBase.

Definition at line 198 of file SoftI2cMaster.cpp.

bool I2cMasterBase::transfer ( uint8_t  addrRW,
void *  buf,
size_t  nbytes,
uint8_t  option = I2C_STOP 
)

Start an I2C transfer with possible continuation.

Parameters
[in]addrRWI2C slave address plus R/W bit. The I2C slave address is in the high seven bits and is ORed with on of the following:
  • I2C_READ for a read transfer.
  • I2C_WRITE for a write transfer.
[in,out]bufSource or destination for transfer.
[in]nbytesNumber of bytes to transfer (may be zero).
[in]optionOption for ending the transfer, one of:
  • I2C_STOP end the transfer with an I2C stop condition.
  • I2C_REP_START end the transfer with an I2C repeated start condition.
  • I2C_CONTINUE allow additional transferContinue() calls.
Returns
true for success else false.

Definition at line 52 of file SoftI2cMaster.cpp.

bool I2cMasterBase::transferContinue ( void *  buf,
size_t  nbytes,
uint8_t  option = I2C_STOP 
)

Continue an I2C transfer.

Parameters
[in,out]bufSource or destination for transfer.
[in]nbytesNumber of bytes to transfer (may be zero).
[in]optionOption for ending the transfer, one of:
  • I2C_STOP end the transfer with an I2C stop condition.
  • I2C_REP_START end the transfer with an I2C repeated start condition.
  • I2C_CONTINUE allow additional transferContinue() calls.
Returns
true for success else false.

Definition at line 80 of file SoftI2cMaster.cpp.

bool SoftI2cMaster::write ( uint8_t  data)
virtual

Write a byte

Note
This function should only be used by experts. Data should be accessed by calling transfer() and transferContinue()
Parameters
[in]databyte to write
Returns
true for ACK or false for NACK

Implements I2cMasterBase.

Definition at line 214 of file SoftI2cMaster.cpp.

Variable Documentation

const uint8_t STATE_REP_START = 1

Repeated start condition transmitted.

Definition at line 42 of file SoftI2cMaster.h.

const uint8_t STATE_RX_ADDR_NACK = 4

Slave address plus read bit transmitted, NACK received.

Definition at line 51 of file SoftI2cMaster.h.

const uint8_t STATE_RX_DATA = 2

Read data transfer active.

Definition at line 45 of file SoftI2cMaster.h.

const uint8_t STATE_STOP = 0

Stop condition transmitted.

Definition at line 39 of file SoftI2cMaster.h.

const uint8_t STATE_TX_ADDR_NACK = 5

Slave address plus write bit transmitted, NACK received.

Definition at line 54 of file SoftI2cMaster.h.

const uint8_t STATE_TX_DATA = 3

Write data transfer active.

Definition at line 48 of file SoftI2cMaster.h.

const uint8_t STATE_TX_DATA_NACK = 6

Data byte transmitted, NACK received.

Definition at line 56 of file SoftI2cMaster.h.