Ds3231 rtc usage


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    'DS3231
    'Can anyone tell me why this code does not work?
    settime:
    sda var portb.6
    scl var portb.5
    cntrl CON $10
    rtc CON %11010000
    SecReg CON $00
    hours = $16
    minutes = $40
    seconds = $00
    month = $01
    date = $04
    year = $16
    day = $02
    I2cwrite sda,scl, rtc, $D0, $00,[seconds,minutes,hours,day,date,month,year,cntrl]
    return

    'This line works fine to read from the DS3231
    I2CRead sda,scl, rtc, secreg,[seconds,minutes,hours,day,date,month,year]
    Last edited by n0yox; - 5th January 2016 at 00:56.

  2. #2
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    See page 159:

    The Address size sent (byte or word) is determined by the size of the variable that is used. If a byte-sized variable is used for the Address, an 8-bit address is sent. If a word-sized variable is used, a 16-bit address is sent. Be sure to use the proper sized variable for the device you wish to communicate with. Constants should not be used for the Address as the size can vary dependent on the size of the constant. Also, expressions should not be used as they can cause an improper Address size to be sent.



    Code:
    I2C_Adr     VAR BYTE
    
    I2C_Adr = $00
    I2cwrite sda,scl, rtc, $D0, I2C_Adr,[seconds,minutes,hours,day,date,month,year,cntrl]
    HTH

  3. #3
    Join Date
    Mar 2008
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    After reading your post I took a look at all of the things you mentioned. While doing this I noticed that I had put the RTC variable in the I2cwrite statement two times .

    This did not work > I2cwrite sda,scl,rtc,$D0,I2C_Adr,[seconds,minutes,hours,day,date,month,year,cntrl]

    This works > I2cwrite sda,scl,$D0,I2C_Adr,[seconds,minutes,hours,day,date,month,year,cntrl]

    I would have looked at that code for a week if you had not helped me!

    Thank You !
    rc

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    Hi ! Can you post your full code for DS3231 ? I intend to build something based on Nokia 3310 display ... (upgrade of this : http://www.picbasic.co.uk/forum/show...083#post129083 )

  5. #5
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    Quote Originally Posted by fratello View Post
    Hi ! Can you post your full code for DS3231 ? I intend to build something based on Nokia 3310 display ... (upgrade of this : http://www.picbasic.co.uk/forum/show...083#post129083 )
    See attached file. I use it as an include.

    Displaying time is like
    Code:
    '----[ ALIAS }-------------------------
    RTC_SDA         Var PORTB.3
    RTC_SCL         Var PORTB.2
    
    '----[ INCLUDES }-------------------------
    INCLUDE "..\_Include\DS3231.pbp"
    
    ...
    
    gosub GetTime
    HSEROUT2  [hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec, 13, 10]
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    Thank You so much !

  7. #7
    Join Date
    Nov 2006
    Location
    Ventura, CA
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    Quote Originally Posted by MichelJasmin View Post
    See attached file. I use it as an include.

    Displaying time is like
    Code:
    '----[ ALIAS }-------------------------
    RTC_SDA         Var PORTB.3
    RTC_SCL         Var PORTB.2
    
    '----[ INCLUDES }-------------------------
    INCLUDE "..\_Include\DS3231.pbp"
    
    ...
    
    gosub GetTime
    HSEROUT2  [hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec, 13, 10]
    Michel, I know it's been a long time since this was posted, but doesn't the statement "GOTO OverDS3231" skip over the entire program? Or is this just a case of me not understanding how include files work? -Jeff

  8. #8
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Ds3231 rtc usage

    Quote Originally Posted by JBKerner View Post
    Michel, I know it's been a long time since this was posted, but doesn't the statement "GOTO OverDS3231" skip over the entire program? Or is this just a case of me not understanding how include files work? -Jeff
    It skips the include file which contains only functions to be called.

Similar Threads

  1. Usage of built-in DAC ?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th December 2014, 06:59
  2. Accurate serin usage?
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th July 2009, 09:36
  3. Interrupt usage
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th April 2008, 17:20
  4. Serin usage?
    By champion in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 24th January 2007, 01:57
  5. HPWM usage with the 18F6520
    By slxrti in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th November 2005, 17:57

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts