+ Reply to Thread
Results 1 to 11 of 11

Thread: Dallas 3231

  1. #1
    Join Date
    Jan 2009
    Posts
    10

    Default Dallas 3231

    Hi All,

    I m having trouble talking to a DS3231 RTC. I have searched and didn't find any posts directly related to this chip. I have been trying sample code from other Dallas RTC's but no luck so far.

    I can talk to the RTC with another uC. Problem is that most of the code is in ASM, so I can't pluck out what I need, I don't grok ASM. I do know the chip is working though, as I can set and read the time.

    Does anyone have a simple snip that works for sure with the 3231? I can post what I have tried so far, but I thought I'd see if anyone had a snip first and waste less of everyones time.

    Very sorry if there are posts addressing this chip, I really did look.

    Jonathan

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    345

    Default Re: Dallas 3231

    The major issues will likely be (in order):
    1) Understanding and implementing I2C communicaitons with a PIC and PBP (and get the hardware correct)
    Lots of Info on the protocol is available online.
    2) How to use the I2C protocol to access the DS3231 specific registers Both to set the device and retrieve data
    The datasheet will help here once you have #1 sorted out.
    3) How to manipulate/convert the received data in PBP do display on an LCD.

    This link may help you in overcoming the issues above. http://www.rentron.com/PicBasic/i2c_communication.htm
    Last edited by SteveB; - 3rd May 2012 at 22:44. Reason: premature posting

  3. #3
    Join Date
    Jan 2009
    Posts
    10

    Default Re: Dallas 3231

    Steve,

    Thanks for the reply. I have used I2C stuff with PICbasic pro before and the display is no problem. I must not be sending it the right commands. As I understand it, with PBP pro which has the built in I2C commands, all I should have to do is something like:

    I2CRead sda,scl,%11010000,$0,[seconds]

    in order to retrieve the seconds data, but I ain't getting it. I can read and set the time from another uC, so I'm pretty sure I have the hardware connected correctly.

    Thanks!

    Jonathan

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    345

    Default Re: Dallas 3231

    Something to remember with the DS3231, you need to write the address of the register you want to read first (no data)
    Then, when you read, you will get the data in the register.

    I've been happier using the hardware I2C. But try these PBP statments:
    :
    I2CWRITE sda, scl, %11010000,%0
    I2CREAD sda, scl, %11010000, [seconds]

  5. #5
    Join Date
    Jan 2009
    Posts
    10

    Default Re: Dallas 3231

    Drat, no luck. I'll keep looking. Thanks!

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    345

    Default Re: Dallas 3231

    I'll offer these up if you are interested in trying the hardware I2C if it's available on your device.

    Some things to mention:
    The path of the include file needs to be specified for where you have it saved.
    This is very bare bones and only ment to get you started in incorporating it into your own code.
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2009
    Posts
    10

    Default Re: Dallas 3231

    Steve,

    I am using a 16F88, which does have hardware I2C. Bummer is, I already made a PCB and populated it and the built in I2C pins are already in use. I think what I'll do is try the code you posted on a breadboard. If it works, I'll see if I can bodger up my board and switch the traces around.


    Thanks a lot for the help! I really appreciate it. I was sure it would be no prob as I have used this chip before and this project is so close to done.


    Jonathan

  8. #8
    Join Date
    Jan 2009
    Posts
    10

    Default Re: Dallas 3231

    Time to add the code I am trying, this has to be something dumb and obvious that I am doing wrong.

    mclr_on
    hs_osc '
    lvp_off
    wdt_off
    protect_off
    define OSC 20
    define shift_pauseus 100
    define I2C_slow 1
    lcdPin var portb.0
    lcdBaud con 84
    lcdAtn con $FE
    lcdOn con $41
    lcdCls con $51
    lcdContrast con $52
    lcdBackLight con $53
    lcdCursor con $45
    lineTwo con $40
    rtc CON %11010000
    sda var porta.1
    scl var porta.0
    SecReg CON $00 ' seconds address (00 - 59)
    ' MSB of SecReg must be set to a 0 to enable RTC
    MinReg CON $01 ' minutes address (00 - 59)
    HourReg CON $02 ' hours address (01 - 12) or (00 - 23)
    DayReg CON $03 ' day address (1 - 7)
    DateReg CON $04 ' date address (01 - 28/29, 30, 31)
    MonthReg CON $05 ' month address (01 - 12)
    YearReg CON $06 ' year address (00 - 99)
    StatusReg CON $0F
    cntrl CON $10'%00000110
    hours var byte
    minutes var byte
    seconds var byte
    days var byte
    month var byte
    year var byte
    date var byte

    hours = 12
    minutes = 55
    seconds = 14
    days = 0
    year = 0
    month = 0

    init:
    serout2 lcdpin,lcdbaud,[lcdAtn,lcdOn,lcdAtn,lcdcls,"DS3231 Test",_
    lcdatn,lcdCursor,lineTwo,"Version 0.1"]
    pause 1000
    'I2cwrite sda,scl, RTC, $D0, $00,[seconds,minutes,hours,days,date,month,year,cntrl]
    'I2Cwrite sda,scl, RTC, StatusReg,[$0]
    'I2CWrite sda, scl, RTC, Secreg,[$00,$00]
    'I2CWrite SDA, SCL, RTC, StatusReg,[$00,cntrl]
    'I2CWrite portb.0, portb.1, $D0, $00, [RTCSec, RTCMin, RTCHour, RTCDay, RTCDate, RTCMonth, RTCYear, RTCCtrl]
    main:
    'I2CRead SDA, SCL, RTC, SecReg, [sec,MINs,hr,day,date,mon,yr]
    'I2CWrite SDA, SCL, RTC, SecReg,[sec,MINs,hr,day,date,mon,yr]
    'I2CRead sda,scl, RTC, secreg,[seconds,minutes,hours,days,date,month,year]
    'i2cread
    I2Cwrite sda,scl,%1101000,$0
    I2CRead sda,scl,%1101000,$0,[seconds]
    'I2CRead sda,scl, RTC, minReg,[minutes]
    serout2 lcdpin,lcdbaud,[lcdatn,lcdcls,dec2 hours,":",dec2 minutes,":",dec2 seconds,_
    lcdatn,lcdcursor,linetwo,dec2 month,"/",dec2 days,"/", dec4 year]
    pause 500

    goto main

  9. #9
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    345

    Default Re: Dallas 3231

    Port A is configured as analog input by default at power on (see note on pg 51 of datasheet), so you will need to include the following configuartion setting to make them digital:
    Code:
    ANSEL = 0
    Check out this thread for more info



    Although this is likely just an issue of copy-paste from your IDE to the forum, but make sure you pay attention to case. For instance, DEFINES are case sensetive.

    And, for furture, you can use the "code" feature to post code. It is the "#" button in the tool bar of the forum posting window, or just type [code] ...your code here... [/code]
    Last edited by SteveB; - 4th May 2012 at 21:38.

  10. #10
    Join Date
    Jan 2009
    Posts
    10

    Cool Re: Dallas 3231

    Steve,

    You da man! Ansel it was. Got it working, thanks so much! And now I can stop beating my head on the keybaord and get back to work.

    Jonathan

  11. #11
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    345

    Default Re: Dallas 3231

    Glad that did the trick!


    Hi, we are pleased to see that you are using our forum.

    We'd like you to become a member of our community. Membership is FREE, please REGISTER and view our forums without these annoying reminders!

    Once registered you may post on the forums, download from the file areas and use the WIKI without interruption.






    But don't rule out more head pounding... it goes with territory. Some of my best thinking is after I have ASDFGHJKL: tattooed across my forehead.

Members who have read this thread : 5

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