ds1307 from f877 to f452 not work


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    microkam's Avatar
    microkam Guest

    Angry ds1307 from f877 to f452 not work

    this code is run ok on 16f877,when i download this code on 18f452 there is one problem that the ds1307 not work, in the same time the 24lc256 on the same bus is working good...whats the problem!!!!


    define osc 4
    DEFINE LOADER_USED 1

    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    DEFINE LCD_LINES 2


    DPIN var PORTC.4 'I2C DATA PIN 24LC256 and ds1307,with 4K7 pull up
    CPIN var PORTC.5 'I2C CLOCK PIN with pulled up resister 4K7


    add var word
    d1 var byte
    d2 var byte
    B0 var byte
    sec var byte
    sec0 var byte
    sec1 var byte
    rtcco var byte
    rtcad var byte

    pause 500
    rtcco=$D0
    rtcad=0
    B0=0
    I2CWRITE DPIN,CPIN,rtcco,rtcad,[B0,B0,B0,B0,B0] ' intilization of ds1307
    lcdout $FE,1," start"
    main:
    pause 1000
    add=0
    d1=9
    I2cWRITE DPIN,CPIN,$A0,add,[d1] 'eeprom write
    pause 30
    I2CREAD DPIN,CPIN,$A1,add,[d2] 'eeprom read
    gosub readtime
    lcdout $FE,1,#d2," ",#sec
    goto main

    readtime:
    rtcco=$D0
    rtcad=0
    I2CREAD DPIN,CPIN,rtcco,rtcad,[B0] 'ds1307 read
    sec0=B0&%00001111
    sec1=B0&%01110000 : sec1=sec1>>4
    sec=sec0+sec1*10
    return
    Last edited by microkam; - 6th July 2005 at 13:37.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    microkam, I notice you make no mention of a 4.7 k pullup on the data line?

    Dave Purola,
    N8NTA

  3. #3
    microkam's Avatar
    microkam Guest


    Did you find this post helpful? Yes | No

    Default

    the data line and clock line is pulled up with 4K7 ohm ,and this code is runing very good on 16f877 ,but idont know whats the problem on 18f452

  4. #4
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Perhaps .....

    DEFINE I2C_SLOW 1

    ..... will solve the problem?

  5. #5
    microkam's Avatar
    microkam Guest


    Did you find this post helpful? Yes | No

    Default

    i did this..
    i defined this
    DEFINE I2C_SLOW 1
    buts no result

  6. #6
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    microkam,

    I can't see anything wrong with your code.

    And since you are saying the EEPROM works fine
    I would assume the DS1307 is faulty
    (or has a bad connection)
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  7. #7
    microkam's Avatar
    microkam Guest


    Did you find this post helpful? Yes | No

    Default

    there is no faulty in ds1307 because before moment i replace the 18f452 with 16f877 on the same program and it run ok ......
    i dont know whats i doing

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Can you try it with a variable instead of a constant in the I2C Address... eg...

    RTC var Byte

    RTC=$D0
    I2CWRITE DPIN,CPIN,RTC,0,[0,0,0,0,0] ' intilization of ds1307

    and likewise in reading...

    I2CREAD DPIN,CPIN,RTC,0,[B0] 'ds1307 read

    there is no need to change between $D0 and $D1 when reading or writing, because PBP manipulates bit zero for you automatically. You only need to concern yourself with the upper seven bits of the address.

    Nobody reads FAQ's... makes me wonder why I spent the time doing them in the first place...http://www.picbasic.co.uk/forum/showthread.php?t=587

  9. #9
    microkam's Avatar
    microkam Guest


    Did you find this post helpful? Yes | No

    Angry

    i edited my programe on the new defined and the ds1307 still not working
    ,i download the new programe on the 16f877 and all thing is ok
    whats the problem!!!
    mel, can you see the new programe and tell me whats the wrong
    Last edited by microkam; - 6th July 2005 at 13:39.

  10. #10
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Melanie,

    you are absolutely right in:
    Quote Originally Posted by Melanie
    there is no need to change between $D0 and $D1 when reading or writing, because PBP manipulates bit zero for you automatically. You only need to concern yourself with the upper seven bits of the address.
    However,
    all variants listed should work:
    (I would always prefer the first one)

    Code:
    RTC CON $D0
    I2CWRITE DPIN,CPIN,RTC,0,[0,0,0,0,0]
    Code:
    RTC var Byte
    RTC=$D0
    I2CWRITE DPIN,CPIN,RTC,0,[0,0,0,0,0]
    Code:
    I2CWRITE DPIN,CPIN,$D0,0,[0,0,0,0,0]
    and even this one
    (Bit0 set with I2CWRITE)
    works since PBP takes care of Bit0:
    Code:
    I2CWRITE DPIN,CPIN,$D1,0,[0,0,0,0,0]
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Similar Threads

  1. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  2. Can't get switch to work
    By JeffnDana in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 4th April 2007, 20:44
  3. DS1307 on fire
    By brid0030 in forum General
    Replies: 6
    Last Post: - 25th November 2006, 02:44
  4. How to set ICD-2 clone to work with PBP?
    By G-R-C in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th October 2006, 02:50
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

Members who have read this thread : 1

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