PDA

View Full Version : Dallas DS3232 Extremely Accurate RTC



Dave-W
02-16-2010, 09:11 AM
Hello All,
I·am just starting to program my BS2P to interface my new DS3232 Date / Time IC.
Here is some code I just started with and I would like to know if I am on the right track or way out in left field. According to PBasic the address is not needed. It says:

·Note that some devices like the PCF8574 do not require an internal address, so this parameter is optional (BS2p firmware 1.3 or later is required to omit the Address parameter).

So, I am using the Slave ID as the Memory address for the DS3232. Will this work?
Will this work?

' {$STAMP BS2p}
' {$PBASIC 2.5}
·
' ================================================== ======================
·
' -----[ Program Description ]---------------------------------------------
·
' This code will interface the BS2p, BS2pe and BS2px to a Dallas DS3232 maybe
·
' -----[ I/O Definitions ]-------------------------------------------------
·
SDA··········· PIN····· 0············· ' I2C Serial Data Line
SCL··········· PIN····· 1············· ' I2C Serial Clock Line
·
' -----[ Variables ]-------------------------------------------------------
·
TimeDate········· ········ VAR····· Byte·········· ' Variable Used To Store Value
DS3232_Start_add··· VAR····· Byte·········· ' DS3232 Start+ counter address to put Data
Counter······················ VAR··· ·· Byte············ ' Loop counter for Data Address
' ------- Preset Data ----------------------------------------------------------
'
DS3232_Start_add···· =$00
Counter· ···················· = 00····
'
I2COUT SDA, ID+COUNTER, [TimeDate]
·
' This will loop until all time and date data has been transferred.

Any suggestions welcome,
Dave

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.

Mike Green
02-16-2010, 09:28 AM
Please read the sticky thread "PLEASE READ BEFORE POSTING PROJECTS! (Completed Projects Forum Guidelines)". Your thread doesn't fit the guidelines for this forum. Better would have been the Sandbox or the Stamp forum.

Dave-W
02-16-2010, 10:01 AM
Mike,
How do I move it? I did not realize I was in the wrong Forum.
Sorry,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.

Mike Green
02-16-2010, 11:19 AM
Only one of the forum administrators can move it. I wanted you to read and understand the guidelines.

I think you need to reread the datasheet for the DS3232, particularly the pictures of the I2C communications and compare those to the descriptions of the various I2C statement of the BS2p series. My reading of the datasheet tells me that the device select code is $D0 and the device behaves otherwise like a 256 byte RAM or EEPROM with one byte of address information given in the I2CIN or I2COUT statements. If you want to read the control/status byte, you'd do:

I2CIN SDA,$D0,$0F,[ statusValue ]

If you want to write to the control/status byte, you'd do:

I2COUT SDA,$D0,$0F,[ controlValue ]

If you want to read or write the SRAM, you'd use addresses $14 through $FF instead of $0F shown above.

Chris Savage
02-16-2010, 08:59 PM
This thread is being moved from the Completed Projects Forum to the BASIC Stamp forum.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage

Parallax Engineering
·

Dave-W
02-18-2010, 10:39 AM
Hello Mike,

Thank you for your input. Now, so I can understand this I re-read the spec sheet several times. Here is the information I do think I understand.

For a Data Write:

Start bit, Slave addess of 1101000 = $68, write command of $00 for slave to read, receive the ACK bit, send word address [ $00 if it is seconds ], receive the ack bit, send the·Data.

Am I on the right track?

Also,

Many thanks to Chris for the forum correction. Next time I will be awake before I post..http://forums.parallax.com/images/smilies/nono.gif

Chris, Great site for information. Goto savagecircuits.com

Dave,





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.

Mike Green
02-18-2010, 10:48 AM
Well, not quite. The I2CIN and I2COUT statements expect that the device address is represented as it would be sent as a byte to the device along with the read/write bit which is provided by the statement. The device address item in the statement would be $D0 as I said (read the description of the statements in the Reference Manual). The I2CIN / I2COUT statements take care of sending the "word" address and handle the ACK bits.

Dave-W
02-18-2010, 11:26 AM
Mike,
Give me a few moments to digest what you have tried to tell me and thank you that you did take your time to explain. However, I will re-read the spec sheet again and look at the BS2 I2c commands again. Thanks much. I do not doubt you, it is me that is in the dark for now. I now know that the ACK is handled by the BS2 command but It may take me a few hours to understand the device address... More reading to do.
Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.