problems with I2C.... and ideas why dosent work?


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    snood's Avatar
    snood Guest

    Default problems with I2C.... and ideas why dosent work?

    okay, i'm using a PIC16F876A and a DS1307 RTC, i have written a short program which should set the time, then loop reading the time to confirm that it is infact set. the problem is when i go to run this in the device... the LCD screen just shows up values with everything reading "00". this to me suggests that i have something wrong with the write commands. here's the offending code:


    TRISC = %11111111
    TRISB = %11111111

    second var byte
    minute var byte
    hour var byte
    day var byte
    date var byte
    month var byte
    year var byte

    ITCDEVICE var byte
    ITCADDRESS var byte

    SDA var PORTC.4
    CLK Var PORTC.3

    LCDOUT var PORTB.0

    ITCDEVICE = $D0
    ITCADDRESS = $00

    second = 0
    minute = 0
    hour = 12
    day = 2
    date = 25
    year = 5

    pause 1000

    I2CWRITE SDA, CLK, ITCDEVICE, ITCADDRESS, [second, minute, hour, day, date, year]

    second = 255 'change variables to make sure it recieves correctly'
    minute = 255
    hour = 255
    day = 255
    date = 255
    year = 255

    loop:

    pause 500

    I2CREAD SDA, CLK, ITCDEVICE, ITCADDRESS, [second, minute, hour, day, date, year]

    serout LCDout, 6,[254,1] 'clears screen'
    serout LCDout, 6,[254,128] 'sets position'
    serout LCDout, 6,[#hour,":",#minute,":",#second] 'displays the read time
    serout LCDout, 6,[254,192] 'next line'
    serout LCDout, 6,["month:",#month," year:",#year] 'displays the read date

    goto loop
    Last edited by snood; - 23rd April 2005 at 16:06.

  2. #2
    @sda's Avatar
    @sda Guest


    Did you find this post helpful? Yes | No

    Default

    Spelling mistake?
    SCL instead of SLK for the I2C variable.

    sda

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi snood,
    Isn't "LCDOUT" a reserved word in PBP? Don't know if that might cause problems.

    Arch

  4. #4
    snood's Avatar
    snood Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Archilochus
    Hi snood,
    Isn't "LCDOUT" a reserved word in PBP? Don't know if that might cause problems.

    Arch
    well i have just actually re-written that for the purpose of the forum, i dont currently have access to my one with the problem... LCDOUT is just what i called it here, it's called "screen" on my actual version, either way, it's not the screen i'm having trouble with, thats working fine, it's just not displaying the "correct" information from the RTC.. i just read in another post something about when the DS1307 is brand new you have to do something to it to make it work, can someone explain this to me? as the above code is being run on a fresh 1307.

    thankyou

    Paul

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


    Did you find this post helpful? Yes | No

    Default

    Snood,

    if you search the Forum for "DS1307" you'll find a number of examples.
    (be honest, you haven't really searched)

    Do you have 4k7 Pullup Resistors on SDA and SCL ?

    For additional Information see: DataSheet
    regards

    Ralph

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



  6. #6
    snood's Avatar
    snood Guest


    Did you find this post helpful? Yes | No

    Default

    ogg dear i never noticed the 4k7 resistor... how vital is this to have? i connect the resistor to the SDA only according to the datasheet, what does the other end of the resistor connect to? +5v?

    and yes ive searched for 1307.

    paul

  7. #7
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Snood,
    Ohh... yeah, those pullups are important! Hook them from the SDA and SCL lines to your positive rail that powers the PIC and 1307.

    Here's a bit from the data sheet about starting up a 'new' 1307:

    "Bit 7 of register 0 [seconds] is the clock halt (CH) bit. When this bit is set to a 1, the oscillator is disabled. When cleared to a 0, the oscillator is enabled."

    Since you set 'seconds' to 0, the clock should be enabled, assuming the the I2C write command is working properly.

    Arch

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by snood
    ogg dear i never noticed the 4k7 resistor...
    No pullUp, No Success
    Quote Originally Posted by snood
    what does the other end of the resistor connect to? +5v?
    what else could you connect a PulUp to?

    Quote Originally Posted by snood
    ...and yes ive searched for 1307.
    Well, then everything should be pretty clear.
    (if you have taken the time to read through the threads)
    Last edited by NavMicroSystems; - 24th April 2005 at 00:25.
    regards

    Ralph

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



Similar Threads

  1. I2C problems
    By Mad_Labs in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th September 2005, 05:22

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