AceWire  0.1.0
Unified interface for selecting different I2C implementations on Arduino platforms
Public Member Functions | List of all members
ace_wire::SimpleWireInterface Class Reference

A software I2C implementation for sending LED segment patterns over I2C. More...

#include <SimpleWireInterface.h>

Public Member Functions

 SimpleWireInterface (uint8_t dataPin, uint8_t clockPin, uint8_t delayMicros)
 Constructor. More...
 
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 start condition. More...
 
void endTransmission () const
 Send stop condition.
 
uint8_t write (uint8_t data) const
 Send the data byte on the data bus, with MSB first as specified by I2C. More...
 

Detailed Description

A software I2C implementation for sending LED segment patterns over I2C.

This has the same API has TwoWireInterface so it can be a drop-in replacement.

The implementation is very similar to SoftTmiInterface because the TM1637 protocol is very similar to I2C. To keep everything simple, so the beginTransmission(), write() and endTransimision() methods are synchronous (i.e. blocking) because interrupts are not used. This means that we can eliminate the send buffer, which saves both flash and static memory.

Definition at line 43 of file SimpleWireInterface.h.

Constructor & Destructor Documentation

◆ SimpleWireInterface()

ace_wire::SimpleWireInterface::SimpleWireInterface ( uint8_t  dataPin,
uint8_t  clockPin,
uint8_t  delayMicros 
)
inline

Constructor.

On AVR processors, delayMicroseconds() is not accurate below 3 microseconds. Some microcontrollers may support better accuracy and may work well with values as low as 1 microsecond.

Parameters
dataPinSDA pin
clockPinSCL pin
delayMicrosdelay after each bit transition of SDA or SCL. Should be greater or equal to 3 microseconds on AVR processors, but may work as low as 1 microsecond on other microcontrollers.

Definition at line 58 of file SimpleWireInterface.h.

Member Function Documentation

◆ begin()

void ace_wire::SimpleWireInterface::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 74 of file SimpleWireInterface.h.

◆ beginTransmission()

void ace_wire::SimpleWireInterface::beginTransmission ( uint8_t  addr) const
inline

Send start condition.

Parameters
addrI2C address of slave device

Definition at line 93 of file SimpleWireInterface.h.

◆ write()

uint8_t ace_wire::SimpleWireInterface::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 123 of file SimpleWireInterface.h.


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