Shop OBEX P1 Docs P2 Docs Learn Events
Ds1307 i2cin i2cout bsp — Parallax Forums

Ds1307 i2cin i2cout bsp

JimKJimK Posts: 21
edited 2010-01-18 13:21 in BASIC Stamp
I was using a DS1307 RTC with the BSP and everything works fine but I have two questions on what the sample code is doing:

Q1. why did they define a constant D1307 as %1101 << 4 vs. %11010000 ?

If I understand the help file correctly the << shift left is the equivilent of %11010000.· Is there some performance gain or was it just to demonstrate the shift left operator ? From a readability viewpoint (at least to me) %11010000 is easier to understand.

Q2. Reading the data sheet on the DS1307 http://datasheets.maxim-ic.com/en/ds/DS1307.pdf it shows the slave address as 1101000 followed by the read/write bit, 0=write and 1=read.· What is not clear to me is the constant DS1307 is defined as "write" but used in both subroutines to read and write using the I2CIN and I2COUT instructions.· In reading the help file on I2CIN and I2COUT it says it overrides the R/W bit so I guess it does not matter ?· I know the stamp has limited variable memory but in my mind I would expect to see two constants defined:

DS1307R········· CON···· %11010001·' read
DS1307W·········CON···· %11010000·' write

Thanks and appreciate any feedback on this.

' =========================================================================
'
'·· File....... SW21-EX33-DS1307.BSP
'·· Purpose.... Real-time-clock interfacing
'·· Author..... (C) 2000 - 2005, Parallax, Inc.
'·· E-mail..... support@parallax.com
'·· Started....
'·· Updated.... 16 AUG 2006
'
'·· {$STAMP BS2p}
'·· {$PBASIC 2.5}
'
' =========================================================================

'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the access and control of an external real-
' time-clock chip, the DS1307.

'
[noparse][[/noparse] I/O Definitions ]
SDA············ PIN···· 0······················ ' I2C serial data line
SCL············ PIN···· 1······················ ' I2C serial clock line
BtnBus········· VAR···· INB···················· ' four inputs, pins 4 - 7

'
[noparse][[/noparse] Constants ]
Ack············ CON···· 0······················ ' acknowledge bit
Nak············ CON···· 1······················ ' no ack bit
DS1307········· CON···· %1101 << 4
.
.
.
.

' Do a block write to clock registers
Set_Clock:
· I2COUT SDA, DS1307, 0, [noparse][[/noparse]STR secs\8]·········· ' update clock registers
· RETURN

' Do a block read from clock registers
Get_Clock:
· I2CIN SDA, DS1307, 0, [noparse][[/noparse]STR secs\8]··········· ' retrieve clock registers
· RETURN

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-18 06:45
    Your understanding is correct, and the difference between CON %1101<< 4 and CON %110010000 is a matter of personal preference. It has no effect at all on the program size or speed. The I2CIN command automatically sets that bit to 1 and I2COUT sets it to zero. It's just built into the command, so you don't have to deal with it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • JimKJimK Posts: 21
    edited 2010-01-18 13:21
    Thank you Tracy
Sign In or Register to comment.