An MSP430 based Clock

[S]impleAvr alerted us about his simple MSP430 based clock. The clock uses a MSP430G2231 controller which comes packaged with the LaunchPad. Since the 4 digit 7 Segment display needs a total of 32 lines for control and the controller has only 10 lines, he uses multiplexing to turn on required segments. Taking advantage of our persistence of vision or POV, the code cheats our eyes in seeing the full time. His code seems to do a lot behind the scenes. Taking cues from his application notes and features, the code can do the following:

  • A simple menu system.
  • Brightness adjustment
  • Push button gets you through current time, alarm on/off and sleep modes.
  • 12H or 24H display
  • An adjustment to make the clock go faster/slower by setting a gain value.
  • Flash saving of setting.
  • Low power Mode

Part list is minimal – One MSP4302231, One push button,  One 4 digit 7 segment display and an optional buzzer.

A schematic is available on his page. His code however will be released based on one condition - disassemble the .elf or .txt for a hidden easter egg. So all you hackers and reverse engineers out there – get going. His site does not allow comments, but his youtube page does. And as always you can leave a comment below.

Schematic

Code

This page will be updated as soon as someone crack that egg.

Update: Code released.(10/3/2010)

38 Comments

  1. I did some cracking and had not found the Easter egg
    But i did find some interesting striping of Hex characters in the ELF,hope someone finds it lol

    Reply
  2. If I may ask, what did you use as a disassembler? I tried loading the .elf file to step through the disassembled code, but since I use TI CCS, it would not recognize it.

    Reply
  3. thank you for your interest.
    i do not have a windows setup, but for CCS you should not use the elf file, instead use the txt file (in ti txt format, never tried it, i don’t have a windows environment).

    to crack the egg, you may want to:

    1. built the project and “poke” around (if u have the LED module handy).
    there are not that many io pins to poke.

    2. use mspdebug as simulator
    (hard way)
    chrisc@t61:~/ti/ez430/3p4w-clock> mspdebug sim
    Simulation started, 0×10000 bytes of RAM

    (mspdebug) prog 3p4w-clock.elf
    Erasing…
    Writing 128 bytes to f800…

    Writing 128 bytes to ff80…
    (mspdebug) reset
    (mspdebug) step
    ( PC: f804) ( R4: 0000) ( R8: 0000) (R12: 0000)
    ( SP: 0280) ( R5: 0000) ( R9: 0000) (R13: 0000)
    ( SR: 0000) ( R6: 0000) (R10: 0000) (R14: 0000)
    ( R3: 0000) ( R7: 0000) (R11: 0000) (R15: 0000)
    __low_level_init:
    f804: b2 40 80 5a 20 01 MOV #0x5a80, &__WDTCTL
    __do_copy_data:
    f80a: 3f 40 02 00 MOV #0×2, R15
    f80e: 0f 93 TST R15
    f810: 05 24 JZ __do_clear_bss
    f812: 2f 83 DECD R15
    (mspdebug)

    3. make use of msp430-objdump against the elf file.
    (easiest way)

    Reply
    • Is your schematic accurate?

      For the MSP430:

      Are pin#3(P1.1), pin#11(TEST), and pin#13(P2.6) connected together?

      Are pin#4(P1.2) and pin#10(RST) connected together?

      For the 4-digit &-segment LED

      Are pin#10 and pin#12 connected together?

      Are pin#3 and pin#10 connected together?

      Reply
      • thanks OCY very glad someone go into the trouble to study the schematic and points out there is a bug.

        (1) Pin 3,11,13 are connected together.
        Pin 3 should be connected to Pin 2 of LED and not connected to Pin 11 and 13. I used Fritzing (still alpha) to generate schematic after I did the layout on the breadboard view. It looks like it failed here (as the breadboard layout looks correct). I will work on it and update the schematic.

        (2) pin 11,13 (TEST) and pin 4,10 (RST) pairs are tied on purpose of convenience. As TEST and RST pins are for debug and programming, they serve no purpose in the circuit. Except that they lies on the same column in the breadboard layout which automatically connects them to led pin 12 and 10. since i don’t want to run excessive wires on the breadboard, i just leave them connected (w/o doing anything). In fact the RST pin will be upsetted by the LED scanning and I had do purposefully enable NMI so that the circuit won’t reset itself (that’s also why the clock needs to be “boot” started via the button).

        (3) the two pair of connected LED pins (10+12) (3+9, fritzing also didn’t show the connection clear here) are done on purpose.
        since the MCU has only 10 IO pins, but we need 12 for full scanning, (i.e. 8 segments x 4 digits) I had to “share” two IO pins to fit.
        the way to do it is to
        a) use pin 13 to drive both LED digit 0 and segment F.
        b) use pin 4 to drive both LED segment “dot” and digit 1.
        i.e. since they are shared and we are doing multiplexing (i.e. rapid displaying one digit at a time), we will only have live w/ the downside of not able to
        . show segment F on digit 0 position.
        . show the “dot” on digit 1 position.

        this is ok as the clock only needs to show 1 or 2 at digit 0 (12H or 24H mode)

        (*) the easy way i found to read the schematic is to mentally stack the LED module on top of the MCU (except pin 1 and 14 which are power pins), this is what’s done physically to built it on the breadboard.

        i.e. MCU pin2-7 connects to LED pin1-6
        and MCU pin8-13 connects to LED pin7-12

        of course then you need to connect “sharing” pins.

        thanks again for pointing out the bug in schematic, i will address it ASAP. this project has been fun to me, hope u enjoy it also.

        Reply
  4. Thanks for the clarification. I will try to crack the Easter Egg — hopefully, finish before Easter ;-)

    Reply
  5. Great project!

    I loved visiting your site and seeing your projects on launchpad. I also work primarily in linux environment and was happy to find your work on msp430 uC’s.

    I remember seeing pictures of one of your projects on comment section on my shabby RTC projecct:
    http://hackaday.com/2010/09/22/matrix-clock-is-a-breadboarding-win/#comments

    Seems like your easter egg has something to do with playing tunes when piezo is connected. I haven’t dug around too much, but a simple symbol table dump shows:

    3p4w-clock.elf: file format elf32-msp430
    70,78c70,76
    < 0000ff9e l O .text 0000000c factor.1382
    < 0000ff50 l O .text 0000004e digit2ports
    < 0000ff4a l O .text 00000006 menu_attrs.1475
    < 0000feec l O .text 00000018 menu_desc
    < 0000ff04 l O .text 0000002a tune
    < 0000ff2e l O .text 00000014 tune_map
    < 0000020c l O .bss 00000001 pos.1537
    < 0000ff42 l O .text 00000004 digit_map2.1539
    0000feb4 l O .text 0000000c factor.1382
    > 0000fe66 l O .text 0000004e digit2ports
    > 0000fe60 l O .text 00000006 menu_attrs.1432
    > 0000fe40 l O .text 00000018 menu_desc
    > 0000020c l O .bss 00000001 pos.1487
    > 0000fe58 l O .text 00000004 digit_map2.1489
    > 0000fe5c l O .text 00000004 digit_map1.1488

    Keep up the good work! I’ll look forward to seeing more cool projects on your site for both avr’s and msp430′s. :-)

    Reply
    • sorry for the very delayed reply.

      the egg is indeed a tune player, it is activated by re-positioning the buzzer from P1.4+P1.3 to P1.3+P1.1.

      great work jbremnant and thanks to all other friends (ocy, jusin, gerry, etc) for spending time on this little game.

      i will update my project page accordingly. anyone interested in doing a video on breaking the egg? if not, i will do the honor in 2 weeks time and have a closure on this.

      Reply
  6. Great project! I realize there are no pins left to use a 32Khz external crystal, so I was wondering how accurate the internal oscillator is, and if there’s much drift with this project?
    thank you again for providing a great project for the MSP430 community!

    Reply
    • apologies for delayed reply.

      on accuracy, the 1Mhz DCO should be more accurate but still got affected by temperature (haven’t time it, but my guess is like 1min off /day). my implementation to use VLO (which can vary between 12-20Khz) at best will do 1 min off/day. i was constantly using it on my bedside during august and i would adjust it may be twice a week before sleep to keep it reasonably right.

      now stepping into october and we had our heaters on, it’s doing worse and i can’t use it anymore (unless u are willing to adjust it everyday). temperature fluctuation is the killer. but i need the VLO to save on battery.

      i’ve since (two weeks ago) add an RTC to the design so that i will be able to use it reliably. i 1st research on DS1307 types and settled on a NXP8563 which is a 1.8-5.5v device and very in-expensive (got 20 pcs from china for $15, i always surrender under quantity discounts)

      i am going to extent the project to include this RTC option. now i am trying to find a good way to have the RTC powered from the same source and do the layout better.

      the upgrade will still fit in a 170 tie-point mini breadboard (but the display will be off centered).

      will provide updates in a timely manner.

      Reply
  7. i’ve put up the original source on my project page, if anyone is interested.

    http://www.simpleavr.com/msp430-projects/3p4w-clock

    also a short video showing how to enable the “egg” tune player.

    http://www.youtube.com/watch?v=HdSO6eGQcnU&feature=mfu_in_order&list=UL

    you will also see added parts (PCF8563 RTC, diode and capacitor for backup) on the video. i am quite happy w/ this addition, before the breadboard was too bland (too few parts). i am making new firmware to use the RTC properly (calender, alarm, etc), will post it when done.
    thanks.

    Reply
  8. I have trying to compile the rtc-clock update but the hex code appears to be to big. I am using mspgcc on Windows. Using Fetpro 430 flash programmer .It says code is too big! 2034 bytes.. Any suggestions. Or what should the makefile look like?

    Thanks.

    like the project.

    Reply
    • glad u enjoy my project, i haven’t play around lately.
      i didn’t use any special c flags to compile but may be the gcc version is different.
      i tried again on my recent cgywin setup via this script

      GCCBIN=/cygdrive/c/mspgcc4-20110312/bin
      PRG=$1
      if [ -z $PRG ]; then
      PWD=`pwd`
      PRG=`basename $PWD`
      fi

      $GCCBIN/msp430-gcc -I$GCCBIN/../msp430/include -Os -mmcu=msp430x2013 -o $PRG.elf $PRG.c
      $GCCBIN/msp430-objdump -DS $PRG.elf > $PRG.lst
      $GCCBIN/msp430-objdump -h $PRG.elf
      $GCCBIN/msp430-size $PRG.elf

      and got this

      rtc-clock.elf: file format elf32-msp430


      text data bss dec hex filename
      1964 68 14 2046 7fe rtc-clock.elf

      you could also look at this thread if u need to optimize for size

      http://www.43oh.com/forum/viewtopic.php?f=5&t=295&p=2352&hilit=code+size#p2352

      Reply
  9. Hello.
    I made your project but I have a problem: figures rarely turn on the display, as display frequency is very small. I flash MSP430G2231 and MSP430F2011 and both do the same. MSPs have written on Windows using the file “3p4w-clock.txt” and FET Pro-430 to Elprotronic and MSP430 Development Tool Launchpad.
    Please help.
    Thanks

    Reply
    • mihai,

      if u see the display flickering slowly, it could mean the clock is slow.
      inside the code, we use the factory calibrated value of 1Mhz for main clock. and we are assuming it is available.

      BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
      DCOCTL = CALDCO_1MHZ;

      u may want to try:

      1. use debugger to check the calibration locations to confirm u have good values there. this forum thread has info on querying the calibrated values http://www.43oh.com/forum/viewtopic.php?f=10&t=234
      2. not sure if u can use a F2011, it might hold up code segments where we read temperature (F20x1 has no ADC/temp sensor), if u has a F2012, it would work as i had tried that.
      3. if u are running on a launchpad, try removing jumpers and isolate the project from the programmer side, we use NMI in a funny way and the launchpad can cause problem.

      *. if still can’t resolve, it’s always good to run a simple led blinker example from the ti example files, just to make sure everything hardware side is ok.

      Reply
      • Hello.
        Thanks for the reply.
        I solved the problem in that we used a test plate with some connectors pins higher than the display. Now I glued the display and all is well.
        I am a Windows user.
        I did and wrote MCUs with FET-Pro430 from Elprotronic. I work frequently with PIC and write in Basic. I recently bought the TI MSP430 Launchpad and I found interesting your project. But it seems to me ambiguous works.
        I tried to load file “3p4w-clock.c” in CCS and IAR but the compilation errors. I do not know how to do in Linux. I want to tell me how to setting time. When I do this:
        -press and is run something like 1222.
        -press once and is 017 short.
        -click once and the temperature is 28C (temperature).
        -press once and turns off the display.
        Now, after I clicked the first time I appeared in 1222, if I pressed long, appears SET. Briefly press can adjust the time (should be always blink, the youtube film, but to me stand out and lights from time to time, if I adjust time). Then adjust ten minutes and then adjust the minutes. After setting, press long for 12H or 24H. After this, press and hold and appear what I set. This is the hour? The clock starts working now? Because after you press short one more time, is 025, then the temperature and then after one more push turns off the display.
        Clock runs with off screen?
        Basically, I have three hits:
        -the first is what I set the
        -second is something like 032
        -third is the temperature.
        Now. no set time progresses, as time goes.
        Advancing only the second display. The temperature is correct. Please, if you do not mind, I set the record straight as it works. Can “3p4w-clock.txt” can file is not good.
        Thanks in advance.

        Reply
        • mahai,

          from what u described, it seems that for some reason the wdt clock is way slow. that is why u do not see the flashing while in setup, and your clock is not advancing every second.

          i do not have a chance to verify the .txt file yet, but will do so later.

          u can try and build (w/ CCS) 3p4w-noegg.c from my website, this version is smaller and had CCS directives, i had tried build it w/ CCS w/o any problem.

          from there it will be easier for u to test / change the code.

          Reply
      • alright,

        got it all figured out.

        after some investigation (basic, tried go through your route) the problem is identified as caused by initial “not-set” value on the ticks each digit stays. this is used to control the brightness (via menu bRi) and should be valued at < 8.

        what happened is that for a brand new chip, the eeprom location carries 0xff, thus each digit stays far longer than it should and appeared slow-mo.

        to fix this, upon power-up, immediately go to the bRi (brightness) setup by pressing long-long-long. inside brightness setup, continue to press short-short-short until the display shows all digits at normal pace.

        it is not apparent to me as i seldom try to flash a new chip and my chip has good values already inside the eeprom.

        although i had made provisions for these in the code where i do check for "sensible" values from eeprom, but i had to comment them out (u can see the comment in the source) as we don't have enough space. w/ mspgcc, the current code stays at 2046 bytes (only 2 bytes left).

        thanks for your interest in my project, hope u enjoy it. i will update my web page regarding this.

        Reply
        • Thanks for keeping your code updated!

          Reply
  10. Hello.
    I managed to write MCU with 3p4w-noegg.c file.
    I loaded Windows CCS, and now it works.
    Thank you for your help.
    All the best.

    Reply
    • The code that is generated by the CCS in my case is larger than 2kB always and so can’t flash the MCU.

      Please inform us how did you do that?

      Reply
  11. I installed the mspgcc and mspdebug using the guide availble on the mylightswitch.com.

    Then I connected the launchpad and run the command “mspdebug rf2500″ I’m getting the following output:

    MSPDebug version 0.16 – debugging tool for MSP430 MCUs
    Copyright (C) 2009-2011 Daniel Beer
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Trying to open interface 1 on 005
    Initializing FET…
    FET protocol version is 30066536
    Configured for Spy-Bi-Wire
    Set Vcc: 3000 mV
    fet: FET returned error code 4 (Could not find device (or device not supported))
    fet: command C_IDENT1 failed
    fet: identify failed
    Trying again…
    Initializing FET…
    FET protocol version is 30066536
    Configured for Spy-Bi-Wire
    Sending reset…
    Set Vcc: 3000 mV
    fet: FET returned error code 4 (Could not find device (or device not supported))
    fet: command C_IDENT1 failed
    fet: identify failed

    Then I tried “mspdebug -d /dev/ttyusb1 uif” this gave me the output:

    Trying to open UIF on /dev/ttyusb1…
    uif: can’t open serial device: /dev/ttyusb1: No such file or directory
    root@arup-laptop:~# mspdebug -d /dev/ttyUSB0 uif
    MSPDebug version 0.16 – debugging tool for MSP430 MCUs
    Copyright (C) 2009-2011 Daniel Beer
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Trying to open UIF on /dev/ttyUSB0…
    uif: can’t open serial device: /dev/ttyUSB0: No such file or directory

    Then tried “mspdebug -d /dev/ttyACM0 uif” output received:

    Trying to open UIF on /dev/ttyACM0…
    Initializing FET…
    uif: read error: Connection timed out
    fet: open failed
    Trying again…
    Initializing FET…
    uif: read error: Connection timed out
    fet: open failed

    When I’m attaching the lauchpad to the PC I’m getting the following message in the /var/log/messages :

    generic-usb 0003:0451:F432.000E: hiddev97,hidraw2: USB HID v1.01 Device [Texas Instruments Texas Instruments MSP-FET430UIF] on usb-0000:00:1d.1-1/input1

    It is not getting recognised as a serial port converter. Is the lauchpad defective?

    Please throw some light.

    Reply
  12. Got it working.

    Compiled the code using IAR. I was unable to flash the MCU with IAR. So, took the o/p of IAR (.d43 file) and flashed it with Elpotronic FET pro 430.
    Worked like a charm. Getting display but some segments are messed up – I think that is due to the breadboard. Will build RTC one on a Veroboard and post the final result.

    Thank you simpleAVR for the support.

    Reply
  13. @arup glad u got it working w/ an Elphotronic FET. the linux programming route is always tricky, older distro may not work, and it’s difficult to get the serial channel work reliably (launchpad is a two channel usb device, FET and serial).
    i haven’t build things for quite a while but am glad there are others like the projects i did.

    Reply
  14. I can’t get into the temperature unit selection – it is under the Adj – right? It is always showing temp in F.

    Also can I use a DS1307 RTC with the MCU?

    Reply
  15. In 3p4w_noegg.c you can use NO_TEMP_CHOICE and METRIC_TEMP to adjust your build. Comment or uncomment the definitions.

    For Rtc you will need a 3.3V chip. No the 1307 but some other 13xx like. U will need to adjust the i2c code.

    Reply
  16. Just wondering if it would be possible to upgrade this sweet little app to the larger 8K msp430g2452? Does that seem doable?

    R.

    Reply
    • @R,

      it is very possible and neat to use a 20pin device. that’s something i wanted to do but lately have no time. i would encourage u to try.
      to begin w/, u just need to recompile the code w/ a new target mcu (g2452). drop it in place (ignore the extra 6 pin at the butt initially).

      after it works,

      . shift the led module to the far-end (butt) of the g2452
      . re-work pin assignments and make them work.
      . now w/ the newly freed p2.6/p2.7 (also xin/xout) attach 32khz crystal.
      . modify code to use “accurate” 32khz crystal timing instead of vlo.
      . still smallest / smallist clock but much accurate.
      . still 4 io pins or adc inputs to add things.

      :)

      if u do, be sure the leave a note here.

      Reply
  17. Hello, very good work. Indeed i plan to make a similar project (which will wake me up with LIGHT :)) but i am an Arduino convert, schemas are good but i need Energia codes to understand what is going on with codes. Can someone publish Energia coded version please ?

    Reply
  18. @sirri

    i am afraid u won’t find an energia version of this project. i had not played w/ energia before but understand it’s like arduino (which i had experienced). the 3p4w clock firmware was made very unique to handle the original limitations of the g2231 mcu. like the mclk is switched from 1mhz / vlo from time to time. and we use the reset pin differently.

    i would suggest may be to look for arduino clock “sketches” and try to convert them for energia. i am sure a lot of people in 43oh.com can help answer questions in energia.

    trying to make the 3p4w clock live under energia will not be natural. it will not look like an energia program even if we make it work.

    if u have questions regarding the 3p4w clock “business” logic, u can find the thread (or start one, i can’t remember if i had a thread for it) and i can try and explain to u.

    thanks for your kind words.

    Reply
  19. Hi simpleavr I have a simple question that I think you can answer me:

    It’s possible to use a 32Mhz crystal instead of the 32khz, or 32Mhz is too much? I found a couple of 32Mhz here at home and if it’s possible to use them it would be awesome :D

    Thanks!

    Reply
    • @canibimao
      no u cannot substitute a 32khz w/ a 32mhz crystal. it’s like a recipe calls for 1 gram of salt and u want to put 1kg, it won’t be tasty. :)

      logically, if u run the frequency 1000 times faster, u won’t have accuracy.
      technically, the mcu cannot use hi-freq crystal, u need external circuitry to feed your high-speed clock into the mcu.

      Reply
      • Thanks for the explanation. I thought that it wouldn’t be possible, but, who knows? It may be need just a simple change on the code to work :)
        I’ll order a couple of 32Khz crystals on ebay and then I’ll see if I can put the clock working.

        Thanks very much for the code and the help :D

        Reply
      • Sorry for bother you again, but I’m with a problem with the rtc clock.

        I’m using Code Composer Studio (CCS) and I get a sintax erros on the last 2 “interrupt” instances. I cant figure out what it is. Can you help me?
        This type of error is also occurring with the TI LaunchBread RGB code :(

        Hope you can understand and help me.

        Reply
        • i don’t use CCS often. what version are u on?
          it’s likely #pragma problems or did u setup your project w/ the right device? g2231, g2553, etc.
          can u cut&paste the error u got? or better, raise it in the 430h forum and post a question there (u do need to register though).

          Reply
          • I use the CCS version 5.3.0.

            I choose the right device on the program and the right library and it gives me a sintax error. It only says that’s a sintax error. There aren’t more details :(

            What program do you recomend me to use with windows? Or should I try with a linux virtual machine?

            Thanks for the help :D I’ll post this on the 43oh forum ;)

  20. Aw, this was an incredibly nice post. Taking a few minutes and actual effort to produce a top notch article… but what can I say… I hesitate a lot and don’t seem to get nearly anything done.

    Reply

Trackbacks/Pingbacks

  1. 3p4w clock updated for 20 pin device » Hallo, here is Pane! - [...] in www.43oh.com [Oct 16, 2012] 3p4w-clk20.c uploaded, to support launchpad v1.5 20pin [...]
  2. Community Highlights - July - The Official MSP430 Blog - Blogs - TI E2E Community - […]  MSP430 based Clock created by SimpleAVR […]

Submit a Comment

Your email address will not be published. Required fields are marked *


× six = 12

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>