AceTMI
0.2.0
Unified interface for selecting different implementations for communicating with a TM1637 LED controller chip on Arduino platforms
|
Class that knows how to communicate with a TM1637 chip. More...
#include <SimpleTmiInterface.h>
Public Member Functions | |
SimpleTmiInterface (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... | |
SimpleTmiInterface (const SimpleTmiInterface &)=default | |
SimpleTmiInterface & | operator= (const SimpleTmiInterface &)=default |
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 SimpleTmiInterface.h.
|
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.
dioPin | pin attached to the data line |
clkPin | pin attached to the clock line |
delayMicros | delay after each bit transition of DIO or CLK |
Definition at line 77 of file SimpleTmiInterface.h.
|
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 SimpleTmiInterface.h.
|
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.
Definition at line 139 of file SimpleTmiInterface.h.