I2C communication
NewBee
Posts: 35
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
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
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.
·
Thanks,
Bob
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
Byte 8 is the first byte of the 56 bytes of non-volatile RAM. Are doing something special with byte 8?
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.
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.