AceWire  0.2.0
Unified interface for selecting different I2C implementations on Arduino platforms
Public Member Functions | List of all members
ace_wire::SimpleWireFastInterface< T_DATA_PIN, T_CLOCK_PIN, T_DELAY_MICROS > Class Template Reference

A version of SimpleWireInterface that uses one of the <digitalWriteFast.h> libraries. More...

#include <SimpleWireFastInterface.h>

Public Member Functions

 SimpleWireFastInterface ()=default
 Constructor.
 
void begin () const
 Initialize the clock and data pins. More...
 
void end () const
 Set clock and data pins to INPUT mode.
 
void beginTransmission (uint8_t addr) const
 Send I2C START condition. More...
 
uint8_t write (uint8_t data) const
 Send the data byte on the data bus, with MSB first as specified by I2C. More...
 
void endTransmission () const
 Send I2C STOP condition.
 
uint8_t requestFrom (uint8_t addr, uint8_t quantity, bool stop=true)
 Prepare to read bytes by sending I2C START condition.
 
uint8_t read ()
 Read byte. More...
 
void endRequest ()
 End requestFrom() by sending I2C STOP condition if 'stop' is 'true'.
 
 SimpleWireFastInterface (const SimpleWireFastInterface &)=default
 
SimpleWireFastInterfaceoperator= (const SimpleWireFastInterface &)=default
 

Detailed Description

template<uint8_t T_DATA_PIN, uint8_t T_CLOCK_PIN, uint8_t T_DELAY_MICROS>
class ace_wire::SimpleWireFastInterface< T_DATA_PIN, T_CLOCK_PIN, T_DELAY_MICROS >

A version of SimpleWireInterface that uses one of the <digitalWriteFast.h> libraries.

The biggest benefit of using digitalWriteFast is the reduction of flash memory size, 500-700 bytes on AVR.

The delayMicroseconds() may not be accurate for small values on some processors (e.g. AVR) . The actual minimum value of T_DELAY_MICROS will depend on the capacitance and resistance on the DATA and CLOCK lines, and the accuracy of the delayMicroseconds() function.

Template Parameters
T_DATA_PINSDA pin
T_CLOCK_PINSCL pin
T_DELAY_MICROSdelay after each bit transition of SDA or SCL

Definition at line 52 of file SimpleWireFastInterface.h.

Member Function Documentation

◆ begin()

template<uint8_t T_DATA_PIN, uint8_t T_CLOCK_PIN, uint8_t T_DELAY_MICROS>
void ace_wire::SimpleWireFastInterface< T_DATA_PIN, T_CLOCK_PIN, T_DELAY_MICROS >::begin ( ) const
inline

Initialize the clock and data pins.

These are open-drain lines, with pull-up resistors. We must not drive them HIGH actively since that could damage the transitor at the other end of the line pulling LOW. Instead, we go into INPUT mode to let the line to HIGH through the pullup resistor, then go to OUTPUT mode only to pull down.

Definition at line 66 of file SimpleWireFastInterface.h.

◆ beginTransmission()

template<uint8_t T_DATA_PIN, uint8_t T_CLOCK_PIN, uint8_t T_DELAY_MICROS>
void ace_wire::SimpleWireFastInterface< T_DATA_PIN, T_CLOCK_PIN, T_DELAY_MICROS >::beginTransmission ( uint8_t  addr) const
inline

Send I2C START condition.

Parameters
addrI2C address of slave device

Definition at line 85 of file SimpleWireFastInterface.h.

◆ read()

template<uint8_t T_DATA_PIN, uint8_t T_CLOCK_PIN, uint8_t T_DELAY_MICROS>
uint8_t ace_wire::SimpleWireFastInterface< T_DATA_PIN, T_CLOCK_PIN, T_DELAY_MICROS >::read ( )
inline

Read byte.

After reading 8 bits, an ACK or NACK will be sent by the master to the slave. ACK means the slave will be asked to send more bytes so can hold control of the data line. NACK means no more bytes will be read from the slave and the slave should release the data line.

Definition at line 154 of file SimpleWireFastInterface.h.

◆ write()

template<uint8_t T_DATA_PIN, uint8_t T_CLOCK_PIN, uint8_t T_DELAY_MICROS>
uint8_t ace_wire::SimpleWireFastInterface< T_DATA_PIN, T_CLOCK_PIN, T_DELAY_MICROS >::write ( uint8_t  data) const
inline

Send the data byte on the data bus, with MSB first as specified by I2C.

This loop generates slightly asymmetric logic signals because clockLow() lasts for 2*bitDelay(), but clockHigh() lasts for only 1*bitDelay(). This does not seem to cause any problems with the LED modules that I have tested.

Returns
0 means ACK, 1 means NACK.

Definition at line 107 of file SimpleWireFastInterface.h.


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