rjbatista / tm1638-library

Automatically exported from code.google.com/p/tm1638-library
141 stars 76 forks source link

reading data #50

Closed gunaone closed 4 years ago

gunaone commented 5 years ago

hi all... is possible to read data what coming out from Mcu to the IC.? that mean read what data from Mcu to Mcu...

maxint-rd commented 5 years ago

Yes, that is possible. Easiest way is to hook up a logical analyzer. If you want to read the data using another MCU you need to write some interrupt driven code to assemble the data bytes following clock and latch pin changes.

gunaone commented 4 years ago

do you have example for that?

actually i want to read the IC from hanging scales.

maxint-rd commented 4 years ago

No I don't have a ready made example. What is the type number on the IC?

gunaone commented 4 years ago

TM1620, I was just about to buy a logic analyzer to try it....

any suggestion to analyze it?

maxint-rd commented 4 years ago

Analyzing is indeed the best step to start. I use one of those cheap Saleae clones. At about $8.- they're perfect for people on a tight budget. If you have plenty to spend you can buy an original (at least 8-channel) with support for multiple analog lines.

According the TM1620 datasheet the 3-pin interface has Din, Clk and Stb. Using the analyzer you can find out how fast these are written and see if the reading matches the datasheet.

Final step for me would be to use an Arduino (if fast enough) with the pinchange interrupt library. The strobe signals new bytes written. On the clock edge I would read Din and construct an array of input bytes. Once strobed you could for instance filter control bytes from data and then output the data on the serial pin (TX) and connect that line to the logical analyser to check if all data is properly captured. Good luck with your project!

gunaone commented 4 years ago

Capture

how i can understand that?

gunaone commented 4 years ago

image

maxint-rd commented 4 years ago

Hi, nice screenshot with good clean signal. It's easy to recognize the individual bytes. You could make the reading easier by setting the data display to numbers instead of characters (ie. HEX/decimal display instead of ASCII). Probably you also need to set data valid on the Clock Leading Edge and set data to Least Significant Bit First instead of MSB-first. From this screenshot it's kind of hard to read the actual values.

Next step would be to read and understand the datasheet. Unfortunately the TM1620 datasheet is only available in Chinese. In the documents folder of my TM16xx library I have added some translated datasheets. Some I translated myself using Google translate. The TM1668 and TM1638 are somewhat similar (same lines), but the TM1620 seems more simple as its lacking support for reading buttons. I suggest you to read the TM1668 translation first and then use Google translate to help you read the TM1620 datasheet.

Just now I also uploaded the Chinese datasheet of the TM1620 to the documents folder. Illustration 1 on page 6 looks very much like the data in your screenshot. On page 3 you can find tables with the various commands and on page 4 the addresses. From that I interpret your screenshot as follows:

byte(s) content
1 command 0x02 (set display mode to 2, i.e. 6 digits of 8 segments)
2 command 0x40 (write data registers)
3-15 command 0xC0 + 12 data bytes (set starting address to 0x00, then write data bytes)
16 command 0x8F (set display on, set pulse-width to 14/16)

Most interesting for you are the 12 data bytes. These will set the segment addresses 0x00 to 0x0B (for digits 1 to 6) to the required segment values. The interpretation of the segments depends on how the segments of the 7-segment LED display are connected to the chip. You could trace this with a multi-meter in continuity mode. I'll leave that segment interpretation to you as a nice exercise you can do on paper. Have fun!

Once you have figured out how to interpret the segment values on paper, you can start to write code on your preferred MCU to do it for you. Assuming the display is always written the same way, the first falling edge of the strobe line is a good starting point of a read/interpret cycle. Good luck with that.

Edit: corrected interpretation of first byte.

gunaone commented 4 years ago

so far, thank alot for your guiding me. i hope stay guide me to learn a lot of basic IC like this.

IMG_20191025_095926 IMG_20191025_104758 IMG_20191025_091735 IMG_20191025_091751

its 0.00KG 24 MHz, 24 M Samples [1]0.zip IMG_20191025_111340

maxint-rd commented 4 years ago

Let me do a bit more of your work... (Note: I corrected the first command in my comment above)

Next step is made using your Saleae Logic samples zip file. This shows you the following 12 data values for the segments:

00 00 00 02 FD 04 7D 06 7D 08 0A 0A

According table (2) on page 4 of the chinese datasheet, these 12 values are for the six digits (GRID1-GRID6). On your paper sketch you showed the relation between SEGx, PIN and segment. Using that you can make this translation table:

what connection
SEGx 12345678 xxxx90xx
pin# 23456789
7-seg FGABDECP

As it appears from the values sampled, the unused lower nibble of the second byte (ie. B0-B3 of the odd addresses) are used as a sequence number, so those can be ignored. By translating the binary values to segment letters the following analysis of the segment data can be made.

digit value binary (LSB-first) segments display value
1 00 00 0 none blank
2 00 02 0 none blank
3 FD 04 10111111 F ABDECP 0.
4 7D 06 10111110 F ABDEC 0
5 7D 08 10111110 F ABDEC 0
6 0A 0A 01010000 not connected n/a

So there you have it. The decimal value of 0.00 as shown on the display. Next exercise for you is to sample a different value and see if you can decode it yourself. Note that when writing down the bits, you need to reverse them to LSB-first, So 7D is not b01111101 but becomes b10111110, lighting up segments FABDEC for the decimal zero.

After that exercise you can connect your MCU and try to capture the values the same as your logical analyzer does. Then the final step is to do more coding and make it work. As my spare time is limited I won't help you to do any of the coding. If you can't do that yourself, perhaps you can spend the time to learn it, or the money to hire someone. Have fun!

P.S. Apologies to Ricardo Batista for using the GitHub issue system as a reverse-engineering forum. Hope you enjoyed the analysis and don't mind the invasion. Feel free to leave your comment as an issue with my TM16xx library on GitHub... :-)

gunaone commented 4 years ago

realy great, i will try it soon. thank u so much @rjbatista @maxint-rd

goes to your post,---->@maxint-rd