ds1307 i2c


Closed Thread
Results 1 to 7 of 7

Thread: ds1307 i2c

  1. #1
    Join Date
    May 2008
    Posts
    10

    Default ds1307 i2c

    Hii.

    I wanna ask a question :

    How can I stop reading from ds1307 and start writing to eeprom on the same sda scl line and after writing start reading from ds1307 again

  2. #2
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default Device id is the answer

    Hi
    Each device you connect to a I2C bus has a 7 bit device address that is set from the factory, some chips has address pins that can be grounded or tied to VDD for additional addressed. Example:

    Eeprom has 1010000 as the generic address with all address pins grounded but you can have many EE2 on the same I2C line if each chip has it's own address. 1010000, 1010001,1010010,1010011 and so on, in the datasheet for each component it is stated how many you can have on the same I2C bus.

    The address to DS1307 is 11010000 7 bits and the last bit is used by PBP to set read or write. Let us say we have 3 chips on one I2C bus, one eeprom, one RTC and one sound chip. The device id is as below.

    EE2=%10100000
    RTC=%11010000
    ISD=%10000000

    To write the the RTC do like this:
    I2C_Adr_B=0
    I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,0]


    I2C_Adr_W=0
    I2CREAD SDA,SCL,EE2,I2C_Adr_W,[I2C_Data(0),I2C_Data(1),I2C_Data(2),I2C_Data(3)]

    as long as the device ID are different you can have as many chips as you like on the same I2C lines (more or less anyway)

    Look at http://www.8052.com/sbc/schematics/DS1307.pdf PAGE 8 and you can see what the datasheet has to say about this.

    Understand?

  3. #3
    Join Date
    May 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default thanks for your reply

    the problem is that I can read data and also I manage to send data to eeprom and ds1307
    but sometimes is says data collision and reset program ...
    it does nor importtant how long I use pause 10 20 50 does not matter ...

    Code:
         i2cread  SDA,scl,$D0,0,[sec,mnt,hour,day,month]
        pause 25 
               if amper>8 then
               Adres = Adres +4 
    
    
               I2CWRITE SDA,SCL,$A0,Adres,[hour,mnt,sec,amper],hatavar
               
                 pause 25
           endif
    
    hatavar:
    		LCDOut $fe,1, "wrt timed out"	' I2C command timed out
    		Pause 100
            RETURN
    Last edited by tamertokgoz; - 13th June 2008 at 10:19. Reason: because of prononciation mistakes

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tamertokgoz View Post
    Hii.

    I wanna ask a question :

    How can I stop reading from ds1307 and start writing to eeprom on the same sda scl line and after writing start reading from ds1307 again
    This looks like interrupt based operation of DS1307 to read the RTC. You cannot do this. What you can do is set a bit variable while you are reading the rtc and use this to avoid writing to the eeprom.

  5. #5
    Join Date
    May 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default not interrupt based

    Quote Originally Posted by Jerson View Post
    This looks like interrupt based operation of DS1307 to read the RTC. You cannot do this. What you can do is set a bit variable while you are reading the rtc and use this to avoid writing to the eeprom.
    the program was written : for to measure frequency and amper and if it is greater then desired value write it to the eeprom. it will be a logger

  6. #6
    Join Date
    May 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Exclamation it is not working also

    Code:
    ADD VAR WORD
    ADDO VAR WORD
    FX VAR WORD
    
    
    sec  var byte
    mnt  var byte
    hour var byte
    day var byte
    month var byte
    year var byte
    
    BOOT:
                LCDOut $fe, 1              
                
                LCDOut "          "
     
                LCDOut $fe,$c0," "
    			pause 1000
    			ADD =10
    
    
     
           
    LOOP:        
         
           i2cread  SDA,scl,$D0,0,[sec,mnt,hour,day,month]
    
        pause 225 
    
               LCDOut $fe, 1              
               Lcdout hex2(hour),hex2(mnt),hex2(Sec), "-", hex2(day),".", hex2(month),"."
     
               LCDOut $fe,$c0,"Okudum Yazcam"
               
               ADD = ADD +1 
               I2CWRITE SDA,SCL,$A0,ADD,[ADD]',BOGUS
               PAUSE 250    
               
           IF BTN1 THEN OKU      
    	GoTo loop					' Do it forever	
    OKU : 
       FOR ADDO =10 TO ADD
            I2CREAD SDA,SCL,$A0,ADDO,[FX]',BOGUS2
                PAUSE 25
            SEROUT2  So,84,[DEC ADDO ,"--", DEC(FX), 13,10]
                PAUSE 50
                
        NEXT
    GOTO LOOP
    bogus:
    		LCDOut $fe,1, "wrt timed out"	' I2C command timed out
    		Pause 100
            RETURN               
    
    bogus2:
    		LCDOut $fe,1, "read timed out"	' I2C command timed out
    		Pause 100
            RETURN               
                    
    End

  7. #7
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    Your program is writing continuously to the eeprom. Totally unadvisable. If you have to do it this way, at least slow it down to around 1 write every minute. The interrupt operation I was suspecting is ruled out after seeing your code. I feel your frequent writes may have damaged the eeprom by now.

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  4. I2C eeprom and DS1307 @40MHz problem
    By ius01 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th July 2007, 07:41
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts