As said earlier in the log, we can't "call" since it doesn't have one. And trying to distinguish "sending only command" and "sending command + data" could be a tedious work. What is tried is to separate these two using two separate state machines, but it ends up breaking the signal (the circled one showing the spurious pulses in the CLK line):
To provide a temporary fix, it has to push both command + command and command + data pairs to the TM1637 using the PIO.
.wrap_target pull block set y, 1 _twoCmds: _startCond: set x, 7 set pins, 1 side 1 [7] set pins, 0 set pins, 0 side 0 _bitShiftLoop: out pins, 1 side 0 nop side 1 jmp x-- _bitShiftLoop side 0 _ackCond: set pins, 0 side 0 nop side 1 nop side 0 [1] _stopCond: set pins, 0 side 1 set pins, 1 side 1 jmp y-- _twoCmds _startCond_sendDigit: set y, 1 set pins, 1 side 1 [7] set pins, 0 set pins, 0 side 0 _sendCmdAndData: set x, 7 _bitShiftLoop_sendDigit: out pins, 1 side 0 nop side 1 jmp x-- _bitShiftLoop_sendDigit side 0 _ackCond_sendDigit: set pins, 0 side 0 nop side 1 nop side 0 [1] jmp y-- _sendCmdAndData _stopCond_sendDigit: set pins, 0 side 1 set pins, 1 side 1
_twoCmds: referred to the two 8-bit of commands (must be command, not data!) being sent.
_startCond_sendDigit: referred to the next 8-bit of command and 8-bit of data being sent.
This arrangement looks tedious since we can't send one command alone, or one command, then continuous data or other way we can imagine. On this restriction, it must be only two commands, then another one command with one data.
To go around this, every time we set a digit on the TM1637 here, we had to:
1.) set the brightness (0x8a -> Display On, 4/16 brightness) [command1]
2.) set the mode (0x44 -> Fixed address) [command2]
3.) set which digit (c0 -> first digit) [command3]
4.) Finally, set the segments (0xff -> all segments on here!) [data1]
Example:
pio_sm_put_blocking(pio0, 0, 0xffc0448a);
Luckily, we can send a maximum of 32-bits into the PIO module, and sending these two pairs actually total to 32-bits. What a coincidence!
So here's the review on the PIO module to drive a TM1637. Due to the modified two-wire interface, distinguishing between send only command, or sending command with accompanying data might be a tedious work, and might not fit into the 32-instruction space on the PIO module. To simplify it, we only send two commands and then one command coupled with one data. Unfortunately, we can't read the data from TM1637 and only write digits to it. This tradeoff is minor because there are no keypads on this module, and we can live with that. :)
Here's the git for this project: https://github.com/nyh-workshop/rpi-pico-tm1637-pio
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.