I2C Hang??

General discussion on mikroBasic.
Post Reply
Author
Message
Chris Yeager
Posts: 73
Joined: 21 Sep 2005 04:23

I2C Hang??

#1 Post by Chris Yeager » 24 Apr 2008 22:22

Is there ever a time when calling this DS1307_GetDateTime function would hang? Somewhere in the I2C routines?

This is part of a library I wrote forthe DS1307 RTC. I'm displaying the time on the 7segment displays using interrupt routine to multiplex them. After a random amount of time 5-10 minutes my program appears to hang up somewhere in this Ds1307_GetDateTime function. The 7Segs will continue to update via the interrupt routine, but the time never changes because this function never returns.

I call this routine once a second, when the clock pulse from the clock goes high.

Also when it hangs... The clock chip is still pulsing.

I determined it is hangin in this function by setting an output pin high right before calling it then setting it low when it returns. Watching this pin it will show it to be high all the time when the "hang occurs". It toggles otherwise.

Any ideas?

Code: Select all


const DS1307_OK               = 0                ' Everything it OK
const DS1307_I2C_ERROR        = 1                ' General I2C Error
const DS1307_TIME_NOT_SET     = 2                ' Time not set

structure DS1307_DateTime                        ' Date time structure
  dim Sec                as byte
  dim Min                as byte
  dim Hr                 as byte
  dim DOW                as byte
  dim Day                as byte
  dim Mnth               as byte
  dim Yr                 as byte
end structure

'******************************************************************************
'* This procedure will get the values in the structure from the DS1307.       *
'******************************************************************************
sub function DS1307_GetDateTime(dim byref ts as DS1307_DateTime) as byte
  dim temp as byte                               ' a temporary variable
                                                 '
  result = DS1307_I2C_ERROR                      ' Set default error
  if I2C_Start = 0 then                          ' Start and continue if ok
    if I2C_Wr(%11010000) = 0 then                ' Send chip address and WRITE
      if I2C_Wr(0x00) = 0 then                   ' Send pointer address
        I2C_Repeated_Start                       ' Send Repeated Start
        I2C_Wr(%11010001)                        ' Send chip address and WRITE
        ts.Sec = I2C_Rd(1)                       ' Get seconds -- ACK
        ts.Min = I2C_Rd(1)                       ' Get minutes -- ACK
        ts.Hr = I2C_Rd(1)                        ' Get hours -- ACK
        ts.DOW = I2C_Rd(1)                       ' Get day of week -- ACK
        ts.Day = I2C_Rd(1)                       ' Get day -- ACK
        ts.Mnth = I2C_Rd(1)                      ' Get month -- ACK
        ts.Yr = I2C_Rd(0)                        ' Get year -- ACK
        I2C_Stop                                 ' Stop
      end if                                     '
    end if                                       '
  end if                                         '
end sub     

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#2 Post by Dany » 15 Aug 2008 16:04

Hi, is it possible to do a test with interrupts switched off during I2c? I had/have the same problem, and that was the solution (not a very good obe but..). Of course I2c routines (in my case I2c_Rd) should not ever become blocking.

Thanks in advance. :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroBasic General”