AceTMI  0.6
Interfaces for communicating with the TM1637 and TM1638 LED controllers on Arduino platforms
Public Member Functions | List of all members
ace_tmi::SimpleTmi1637Interface Class Reference

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

#include <SimpleTmi1637Interface.h>

Public Member Functions

 SimpleTmi1637Interface (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-like start condition.
 
void stopCondition () const
 Generate the I2C-like stop condition.
 
uint8_t write (uint8_t data) const
 Send the data byte on the data bus, with LSB first instead of the usual MSB first for I2C. More...
 
uint8_t read () const
 Read the data byte on the data bus, with LSB first instead of the usual MSB first for SPI. More...
 
 SimpleTmi1637Interface (const SimpleTmi1637Interface &)=default
 
SimpleTmi1637Interfaceoperator= (const SimpleTmi1637Interface &)=default
 

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 SimpleTmi1637Interface.h.

Constructor & Destructor Documentation

◆ SimpleTmi1637Interface()

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

Constructor.

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

Parameters
dioPinpin attached to the data line
clkPinpin attached to the clock line
delayMicrosdelay after each bit transition of DIO or CLK

Definition at line 77 of file SimpleTmi1637Interface.h.

Member Function Documentation

◆ begin()

void ace_tmi::SimpleTmi1637Interface::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 96 of file SimpleTmi1637Interface.h.

◆ read()

uint8_t ace_tmi::SimpleTmi1637Interface::read ( ) const
inline

Read the data byte on the data bus, with LSB first instead of the usual MSB first for SPI.

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
the data byte

Definition at line 176 of file SimpleTmi1637Interface.h.

◆ write()

uint8_t ace_tmi::SimpleTmi1637Interface::write ( 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
1 if device responded with ACK, 0 for NACK. (This retains consistency with AceWire's I2C write() methods which return the number of bytes transfered.)

Definition at line 141 of file SimpleTmi1637Interface.h.


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