Shop OBEX P1 Docs P2 Docs Learn Events
I2C communication — Parallax Forums

I2C communication

NewBeeNewBee Posts: 35
edited 2010-06-14 13:54 in BASIC Stamp
Hi,

I need to use a· for loop to update sequential addresses on a DS1307 by·using the loop counter to step through the addresses.· I'm getting intermitten results using the decimal loop counter for the HEX address especially when I index to address $08 (RAM).

Here's what I'm trying to do.

Set_Clock:
· FOR cntr = 0 TO·8
··· DecConvert· = (datearray(cntr) / 10 << 4) + (datearray(cntr) // 10) ' decimal to BCD
··· I2COUT SDA, DS1307, cntr, [noparse][[/noparse]DecConvert]···································· ' update clock registers
'··· PAUSE 100
· NEXT
· RETURN

' Do a block read from clock registers
Get_Clock:
· FOR cntr = 0 TO·8
··· I2CIN SDA, DS1307, cntr, [noparse][[/noparse]DecConvert]·········································' retrieve clock registers
··· datearray(cntr) = DecConvert.NIB1 * 10 + DecConvert.NIB0············· ' BCD to decimal
'··· PAUSE 100
· NEXT
If this code is ok then I'm very confused about my intermitten operation problem.

Thanks,

Bob

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2010-06-12 17:01
    NewBee

    Have you tried 0 to 9 ?This would give you an extra place for the decimal point. I'm "grasping at straws" here,But it might help.

    ·This would be in the DEC to BCD loop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA


    want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___


    You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.

    ·
  • NewBeeNewBee Posts: 35
    edited 2010-06-12 17:43
    Thanks for your help, the code is fine, the problem was not understood.· Therefore the was all the more illusive.

    Thanks,

    Bob
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-06-12 20:57
    What do you mean by, "intermittent operation" and, "especially when I index to address $08 (RAM)." What happens?

    I don't see anything wrong with your code. The cntr variable is fine as a loop counter and as an address into the DS1307.

    Is the chip set up with 5 volt power, the backup battery, and pullup resistors to Vdd on SDA and SCL?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2010-06-12 22:16
    The clock settings use 8 bytes 0 thru 7.

    Byte 8 is the first byte of the 56 bytes of non-volatile RAM. Are doing something special with byte 8?
  • NewBeeNewBee Posts: 35
    edited 2010-06-12 23:22
    Tracy,

    Actually the clock system works fine.· The code you see initializes the registers 0-7 properly.· I'm trying to use register 8, first byte of SRAM as an indicator the user has already set the clock inorder to prevent reloading of default date & time parameters.· The problem is I·can never get out of register 8 what I put in to it.· It also appears register 8·clear at·power down.· I'm using the 28138 prof dev board with a 2p40.· I just received the environmment about a month·ago so I don't think its a hw prob.
  • NewBeeNewBee Posts: 35
    edited 2010-06-14 13:54
    Hi,

    Just a quick follow up to let everyone know I actually had problems in my clockset and clok get functions. Not with the device communication as indicated in this post.
Sign In or Register to comment.