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::SimpleTmi1638Interface Class Reference

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

#include <SimpleTmi1638Interface.h>

Public Member Functions

 SimpleTmi1638Interface (uint8_t dioPin, uint8_t clkPin, uint8_t stbPin, uint8_t delayMicros)
 Constructor. More...
 
void begin () const
 Initialize the DIO, CLK and STB pins. More...
 
void end () const
 Set pins to INPUT mode.
 
void beginTransaction () const
 Generate the SPI-like start condition.
 
void endTransaction () const
 Generate the SPI-like stop condition.
 
void write (uint8_t data) const
 Send the data byte on the data bus, with LSB first instead of the usual MSB first for SPI. 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...
 
 SimpleTmi1638Interface (const SimpleTmi1638Interface &)=default
 
SimpleTmi1638Interfaceoperator= (const SimpleTmi1638Interface &)=default
 

Detailed Description

Class that knows how to communicate with a TM1638 chip.

It uses a 3-wire (bidirectional DIO, CLK, and STB) protocol that is similar to SPI electrically. the DIO pin is a PMOS open-drain line 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 it is an open-drain, we must make sure that the microcontroller does not actively drive this line 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 TM1638 is similar to SPI in the following ways:

The difference is:

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

Definition at line 61 of file SimpleTmi1638Interface.h.

Constructor & Destructor Documentation

◆ SimpleTmi1638Interface()

ace_tmi::SimpleTmi1638Interface::SimpleTmi1638Interface ( uint8_t  dioPin,
uint8_t  clkPin,
uint8_t  stbPin,
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 delayMicros 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 DIO data line
clkPinpin attached to the CLK clock line
stbPinpin attached to the STB strobe line
delayMicrosdelay after each bit transition of CLK

Definition at line 76 of file SimpleTmi1638Interface.h.

Member Function Documentation

◆ begin()

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

Initialize the DIO, CLK and STB pins.

DIO is an open-drain line with pull-up resistors. We must not drive it 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 SimpleTmi1638Interface.h.

◆ read()

uint8_t ace_tmi::SimpleTmi1638Interface::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 168 of file SimpleTmi1638Interface.h.

◆ write()

void ace_tmi::SimpleTmi1638Interface::write ( uint8_t  data) const
inline

Send 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.

Definition at line 135 of file SimpleTmi1638Interface.h.


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