Shop OBEX P1 Docs P2 Docs Learn Events
Getting DS1302 object to run in the attached program — Parallax Forums

Getting DS1302 object to run in the attached program

djtdjt Posts: 19
edited 2010-01-04 04:25 in Propeller 1
I have put together a series of modified objects obtained from the object exchange web site. (See attachment 1).The combined modified objects run OK and give me the data I want. ·I now want to add the date and time when the data (Temperature ,REL Humidity· dew point and light readings) are obtained.· I have attempted to incorporate the DS1302 object (See attachment 2) into attachment 1 with no success. ·Attachment 3 shows my current try. What am I doing wrong? Any help would be greately appreciated.

Thank's,· djt

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-03 09:15
    Hello djt,

    first use the archive function of the propeller-tool to create a zip-archive that contains ALL *.Spin-files that were needed to compile your project.

    You are a lucky guy that I downloaded the other *.SPIN-files from earlier questions you had.

    if you take a look into the file DS1392_full-demo you see two initial calls of the object

      '==================================================================================
      'call this function each time the propeller starts
      rtc.init( 4, 5, 6 )                             'ports Clock, io, chip enable
    
      '==================================================================================
      'call this function only after DS1302 power on
      rtc.config                                      'Set configuration register
    
    



    In your code this initialisation is missing

    best regards

    Stefan
  • djtdjt Posts: 19
    edited 2010-01-03 21:36
    Hello StefanL38,

    Thank you for your reply. I probably removed the two items as I was trying to get the program to work and forgot to return them. I've re-installed these items and the program runs. Unfortunately, I think I phrased my original questions incorrectly. The program returns all results including the time and date, but the time and date results are 00:00:00 00 00 00 00.

    I have not found how to add the starting time and date to the DS1302_full program. I have added them to the DS1302_full_demo program, but when I use that object (DS1302_full_demo)instead of the DS1302_full object in the SenirionDemoLight1 program I get an error(need Subroutine)·in the following line in the SensirionDemoLight1 program:

    ····· rtc1.readTime( @hour, @minute, @second )

    I am now using an object that has a method in another object. I'm lost!!
    I hate to bother you with these questions, but you have been extreemly helpful in the past and I hope you see your way to helping a·neophite·continue to gain knowledge in this fascinating but complex field.

    Thank's, djt
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-04 04:25
    Hello djt,

    do you get 00:00:00 00 00 00 00 ALL the time or only if you start your code

    and then it returns
    00:00:01 00 00 00 00
    00:00:02 00 00 00 00
    00:00:03 00 00 00 00
    00:00:04 00 00 00 00
    ....

    This file DS1302_full.spin is some kind of a driver that provides functionality to interact with the DS1302-chip.
    This file DS1302_full.spin contains the subroutines that YOU have to call to to interact with the DS1302-chip.

    Everytime you use an object-file you leave this object-file ITSELF as it is. Never ever do ANY changes to an objectfile ITSELF


    The file DS1302_full_demo.spin is a MAIN-program that does calling the subroutines of the file DS1302_full.spin

    Inside DS1302_full_demo.spin there is a call of the method rtc.setDatetime

    You have to call the method rtc.setDatetime INSIDE of the *.SPIN-file that is YOUR main-program.

    Maybe you can imagine objectfiles like DS1302_full.spin as a toolbox with several tools in it.

    If you want to use them at a friend you take the toolbox into your car and take it to your friend.
    At your friend you take out a tool to use it.

    Now to stay in the picture. If you would load into your car the "At your friend you take out a tool" this will surely not work
    as you can not "load" an imaterial "doing" into your car. And here the picture is not so good. (but the best I have handy in my mind at the moment)

    So again the file DS1302_full.spin is the toolbox containing the tools.

    DS1302_full_demo.spin is the house of person A with the toolbox DS1302_full.spin to use it in the house of Person A

    SensirionDemoLight1.spin is YOUR house and you have to buy a toolbox of type DS1302_full.spin and put it into YOUR house so that you have
    all tools of DS1302_full.spin handy.

    If you want to know what tools the toolbox DS1302_full.spin has you have to open the file DS1302_full.spin and take a look inside.
    Now here the analogon "toolbox" does not fit in every detail.

    inside The file DS1302_full.spin you find the following methods (subroutines)

    PUB command(clock_or_ram, register, r_or_w)
    PUB init( inClk, inIo, inCe ) 
    PUB config
    PUB setDatetime( _mth, _day, _year, _dow, _hr, _min, _sec )
    PUB readDate( _day, _mth, _year, _dow )
    PUB readTime( _hr, _min, _sec ) | tmp1, tmp2
    Pub read( cmd ) | i
    Pub write( cmd, data ) 
    PUB writeN(cmd, dataPtr, n)|i
    Pub readN(cmd, dataPtr, n)|i
    PRI readByte|i
    PRI writeByte( cmd ) | i  
    PRI bin2bcd(dataIn) | tmp
    PRI bcd2bin(dataIn)
    
    



    from these you only need

    PUB init( inClk, inIo, inCe ) 
    PUB config
    PUB setDatetime( _mth, _day, _year, _dow, _hr, _min, _sec )
    PUB readDate( _day, _mth, _year, _dow )
    PUB readTime( _hr, _min, _sec ) | tmp1, tmp2
    
    



    ATTENTION the above lines are the DEFINITION of the tools NOT the USE of them.

    How you USE them is shown in the file DS1302_full_demo.spin


      '==================================================================================
      'call this function each time the propeller starts
      rtc.init( 4, 5, 6 )                             'ports Clock, io, chip enable
    
      '==================================================================================
      'call this function only after DS1302 power on
      rtc.config                                      'Set configuration register
    
      '==================================================================================
      'set time
      rtc.setDatetime( 09, 22, 09, 3, 20, 20, 00 )    'month, day, year, day of week, hour, minute, second
                                                            
      '==================================================================================
    ....
        rtc.readTime( @hour, @minute, @second )     'read time from DS1302
        rtc.readDate( @day, @month, @year, @dow )   'read date from DS1302
    
    



    the other PUB-methods are sub-sub-routines (like small parts of a complex tool) that are nescessary for the function of the tool but you use the tool as a WHOLE thing and not some small parts of it

    by the way
    did you work through the Propeller Education Kit Labs Fundamentals Version 1.1

    found here C:\Program Files\Parallax Inc\Propeller Tool v1.2.6\Examples\PE Kit\Propeller Education Kit Labs-Fundamentals v1.1.pdf
    If not it is highly recommended as you leaved the area of small blinking programs long ago and work with programs complex like this

    OBJ
      term          : "FullDuplexSerial"
      sht           : "Sensirion"
      fp            : "FloatString"
      f             : "Float32"
      light         :"tsl230_pi"
      LCD1          : "LCD_16x2_4Bit"
       SN           : "Simple_Numbers"
      rtc1          : "DS1302_full"
    
    



    best regards

    Stefan
Sign In or Register to comment.