Shop OBEX P1 Docs P2 Docs Learn Events
i2cread pause required? SB/B — Parallax Forums

i2cread pause required? SB/B

Chicago MikeChicago Mike Posts: 88
edited 2008-11-16 09:18 in General Discussion
I'm doing a number of reads from an i2c clock, and it seems, on a hard reboot sometimes this read is getting cut short and operating as a write, scrambling things up. Below is the subroutine I made which is getting run 10 times in a row.
sub rtc_read_byte
    temp2 = __PARAM1
    i2cstart RtcSda
    temp = RtcId
    temp.0 = 0
    i2csend rtcsda, temp
    i2csend rtcsda, temp2
    i2cstart RtcSda
    temp = RtcId
    temp.0 = 1
    i2csend rtcsda, temp
    i2cRecv rtcsda, temp, Nak
    i2cstop rtcsda
'    I think this below pause fixed it. 
    pause 30
    return temp
    endsub 




Notice the pause I added, which seemed to solve this. My questions is, is there a mimimum time I should be waiting inbetween subsiquent read and write operations? I seem to remember hearing something like this before? Anyone know the minimum, or at least someone else seen this? It only seems to a happen after a hard reboot and on the FIRST read.

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-11-16 09:18
    The data sheet for your RTC should provide timing specs. The chip may have some internal start-up delay with its oscillator that is causing you trouble.
Sign In or Register to comment.