TM1637 driver for STM8 - Page 1
Forum section: electronics / general

author: mgolab7
author_rank: Newbie
timestamp: April 09, 2022, 02:40:27 pm
content: Hi,I am a beginner hobbyist if it comes to both electronics and microcontrollers.I really need an advice from someone more experienced.I started my adventure with STM8 and next step for me is to learn how to create my own drivers based on data sheet. I decided to go with TM1637 based 7-segment display. The module i own is HW-069 v1.2.I am using this datasheet for reference:https://www.datasheetq.com/datasheet-download/853530/1/ETC/TM1637The problem is that i already wrote a code which creates clk and data output exactly like in the section "Write SRAM data in address auto increment 1 mode" from the datasheet and nothing lights up on display, tested on two pieces of hardware.I would like to ask anyone experienced with writing drivers or maybe this particular IC for advice if there is anything i'm missing or maybe i'm making some fundamental mistake here.I have tried both 3v3 and 5v for VCC of this module, STM8 pins are set as open drains. I also noticed that even though there is no "stop" written in the datasheet example after "data" bytes it looks like there should be one so i tested with and without as well.I am connecting CLK and DIO right in to input of TM1637 as since scope returned 5v on those i assume those are pulled up on module.I am attaching scope output edited to look like logic analyzer and the analyzer output as well (in the scope output there are 4 bytes of data but i tested with 6 as well).Please take a look at those and let me know if there are any mistakes as for me it looks exactly alike to example "Write SRAM data in address auto increment 1 mode" yet i still cant get it to work.Thank You in advance for help.

author: rhodges
author_rank: Frequent Contributor
timestamp: April 09, 2022, 03:09:36 pm
content: You can get my tm1637 library and other support files here:https://github.com/unfrozen/stm8_libsHope this helps!

author: mgolab7
author_rank: Newbie
timestamp: April 09, 2022, 06:06:56 pm
content: Thanks for the reply i will definitely check Your library but I'm not really that advanced if it comes to C programming and it might take a while before i even get it to work for me.So before that maybe You could at least take a quick look the scope dump and advice if it looks decent like maybe im missing a duty cycle guidelines or anything like that. I don't use any timers so it differs in many places. I want to be able to create such drivers for other IC's and its important to me to learn as much as i can so any hint is appreciated.

author: mgolab7
author_rank: Newbie
timestamp: April 09, 2022, 08:54:06 pm
content: I managed to solve this. It turns out this IC takes reading from lowest bit. A minor adjustment to ACK and data reverse was a fix.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: April 10, 2022, 01:14:41 am
content: Are you writing code to bit-bang the communication protocol? You don't need to - it's essentially just standard I2C, even though they call out in the datasheet that it "is not equal to I2C bus protocol totally". The command byte simply becomes the I2C slave address.For example, to send a 'display control' command to change brightness level to 14/16, you would use a slave address of 0x87 (0b10000111). That is, a base command value of 0x80 (in bits B6,B7) specifying 'display control' command, plus the brightness level in the least-significant 3 bits (B0-B2). All other bits are set to zero. Note that that is thefullslave address, already including the nominal R/W bit. If you're using some kind of library/framework (e.g. ST SPL), you might need to mask off and specify the R/W bit separately. Otherwise, for bare-metal STM8 programming, just put the value in the I2C_DR register as-is.Of course, because the command byte becomes the slave address, it means you cannot have more than one TM1637 chip on the same I2C bus, because there is no per-chip unique element to the command byte. But it might not stop you having other proper I2C devices on the bus - you just have to ensure the other devices' slave addresses never clash with any of the permutations of command byte values of the TM1637. Basically any device with zeroes in the two MSb of the address (i.e. 0b00xxxxxx) would be able to coexist.

author: mgolab7
author_rank: Newbie
timestamp: April 10, 2022, 09:26:19 am
content: Hi,Thank You for the hint. Yes - i was bit-banging this protocol. I am not familiar with STM8 libraries tat well even though i had a chance to use I2C with 2x8 display - that was copy:paste code from some tutorial.This was my attempt to understand and apply the knowledge from datasheet as a start to manage such task in future. I will definitely try Your method as I2C is often used from what i already noticed.