AceTMI  0.1.0
Unified interface for selecting different implementations for communicating with a TM1637 LED controller chip on Arduino platforms
Public Member Functions | List of all members
ace_tmi::SoftTmiInterface Class Reference

Class that knows how to communicate with a TM1637 chip. More...

#include <SoftTmiInterface.h>

Public Member Functions

 SoftTmiInterface (uint8_t dioPin, uint8_t clkPin, uint8_t delayMicros)
 Constructor. More...
 
void begin () const
 Initialize the dio and clk pins. More...
 
void end () const
 Set dio and clk pins to INPUT mode.
 
void startCondition () const
 Generate the I2C start condition.
 
void stopCondition () const
 Generate the I2C stop condition.
 
uint8_t sendByte (uint8_t data) const
 Send the data byte on the data bus, with LSB first instead of the usual MSB first for I2C. More...
 

Detailed Description

Class that knows how to communicate with a TM1637 chip.

It uses a 2-wire (Clock and a bidirectional DIO) protocol that is similar to I2C electrically. Both the Clock and Data pins are open-drain which means a single transitor on either the master or slave can pull the line LOW, but a pull-up resisotr is required to set the line HIGH. Because these are open-drain, we must make sure that the microcontroller does not actively drive these lines HIGH, otherwise, the output pin of the MCU at 5V (HIGH) becomes directly connected to the 0V (LOW) of the transistor on the device pulling it LOW, with no current limiting resistor. Either of MCU or the device can become damaged. To set the line HIGH or LOW, we set the output level to LOW, then use the pinMode() function to either INPUT (to get a HIGH value) or OUTPUT (to get a LOW value).

The logical protocol of the TM1637 is similar to I2C in the following ways:

The difference is:

Since the protocol does not match I2C, we cannot use the hardware I2C capabilities of the microcontroller, so we have to implement a software version of this protocol.

Definition at line 63 of file SoftTmiInterface.h.

Constructor & Destructor Documentation

◆ SoftTmiInterface()

ace_tmi::SoftTmiInterface::SoftTmiInterface ( uint8_t  dioPin,
uint8_t  clkPin,
uint8_t  delayMicros 
)
inlineexplicit

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
dioPinpin attached to the data line
clkPinpin attached to the clock line
delayMicrosdelay after each bit transition of DIO or CLK. 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 78 of file SoftTmiInterface.h.

Member Function Documentation

◆ begin()

void ace_tmi::SoftTmiInterface::begin ( ) const
inline

Initialize the dio and clk 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 97 of file SoftTmiInterface.h.

◆ sendByte()

uint8_t ace_tmi::SoftTmiInterface::sendByte ( uint8_t  data) const
inline

Send the data byte on the data bus, with LSB first instead of the usual MSB first for 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 140 of file SoftTmiInterface.h.


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