Welcome
Username or Email:

Password:


Missing Code




[ ]
[ ]
Online
  • Guests: 9
  • Members: 0
  • Newest Member: omjtest
  • Most ever online: 396
    Guests: 396, Members: 0 on 12 Jan : 12:51
Members Birthdays:
One birthday today, congrats!
Vaxian (17)


Next birthdays
05/21 Dalus (34)
05/21 Kizmo (37)
05/22 Skynet (32)
Contact
If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.


Special Thanks To:
  • Aaron Holmes
  • Aaron Wheeler
  • Adam Horden
  • Alan Scrimgeour
  • Andre
  • Andrew Haynes
  • Anonymous000
  • asabase
  • Austin Weil
  • barney
  • Barry
  • Bert Hickman
  • Bill Kukowski
  • Blitzorn
  • Brandon Paradelas
  • Bruce Bowling
  • BubeeMike
  • Byong Park
  • Cesiumsponge
  • Chris F.
  • Chris Hooper
  • Corey Worthington
  • Derek Woodroffe
  • Dalus
  • Dan Strother
  • Daniel Davis
  • Daniel Uhrenholt
  • datasheetarchive
  • Dave Billington
  • Dave Marshall
  • David F.
  • Dennis Rogers
  • drelectrix
  • Dr. John Gudenas
  • Dr. Spark
  • E.TexasTesla
  • eastvoltresearch
  • Eirik Taylor
  • Erik Dyakov
  • Erlend^SE
  • Finn Hammer
  • Firebug24k
  • GalliumMan
  • Gary Peterson
  • George Slade
  • GhostNull
  • Gordon Mcknight
  • Graham Armitage
  • Grant
  • GreySoul
  • Henry H
  • IamSmooth
  • In memory of Leo Powning
  • Jacob Cash
  • James Howells
  • James Pawson
  • Jeff Greenfield
  • Jeff Thomas
  • Jesse Frost
  • Jim Mitchell
  • jlr134
  • Joe Mastroianni
  • John Forcina
  • John Oberg
  • John Willcutt
  • Jon Newcomb
  • klugesmith
  • Leslie Wright
  • Lutz Hoffman
  • Mads Barnkob
  • Martin King
  • Mats Karlsson
  • Matt Gibson
  • Matthew Guidry
  • mbd
  • Michael D'Angelo
  • Mikkel
  • mileswaldron
  • mister_rf
  • Neil Foster
  • Nick de Smith
  • Nick Soroka
  • nicklenorp
  • Nik
  • Norman Stanley
  • Patrick Coleman
  • Paul Brodie
  • Paul Jordan
  • Paul Montgomery
  • Ped
  • Peter Krogen
  • Peter Terren
  • PhilGood
  • Richard Feldman
  • Robert Bush
  • Royce Bailey
  • Scott Fusare
  • Scott Newman
  • smiffy
  • Stella
  • Steven Busic
  • Steve Conner
  • Steve Jones
  • Steve Ward
  • Sulaiman
  • Thomas Coyle
  • Thomas A. Wallace
  • Thomas W
  • Timo
  • Torch
  • Ulf Jonsson
  • vasil
  • Vaxian
  • vladi mazzilli
  • wastehl
  • Weston
  • William Kim
  • William N.
  • William Stehl
  • Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Forums
4hv.org :: Forums :: Computer Science
« Previous topic | Next topic »   

Problem interfacing DS1307 real-time clock with PIC16F88

Move Thread LAN_403
TheMerovingian
Mon Nov 30 2009, 04:19PM Print
TheMerovingian Registered Member #14 Joined: Thu Feb 02 2006, 01:04PM
Location: Prato/italy
Posts: 383
As a first step in building a datalogging anemometer i need to inferface DS1307 real-time clock with PIC16F88 by I2C in picbasic.

I am simulating a simple circuit with an LCD connected to the PIC and the clock connected to PORTB.6 (SDA) and PORTB.7 (SCL) using software I2C. But the reading procedure gives only random garbage.

What do you think?

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : Jonathan FIlippi                                  *
'*  Notice  : Copyright (c) 2009 CC free license                *
'*          : All Rights Reserved                               *
'*  Date    : 30/11/2009                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
ANSEL = %00000000
TRISA = %00000000
TRISB = %00000000

PORTA = %00000000
PORTB = %00000000

DEFINE OSC 20   'crystal oscillator f = 20MHz

Define LCD_BITS 4 'Set LCD Bus Size (4 or 8)
DEFINE LCD_DREG PORTB ' Set data pin of LCD to PORTB
DEFINE LCD_DBIT 0 ' PORTB.0-PORTB.3
DEFINE LCD_RSREG PORTB ' Set RS bit of LCD to PORTA
DEFINE LCD_RSBIT 4 ' PORTA.0
DEFINE LCD_EREG PORTB ' Set E bit of LCD to PORTA
DEFINE LCD_EBIT 5 ' PORTA.1
DEFINE LCD_LINES 2 ' 2 Lines LCD
'DEFINE  I2C_SLOW 1
'DEFINE  I2C_HOLD 1 

SYMBOL SDA = PORTB.6
SYMBOL SCL = PORTB.7


SECS var byte 
MINS var byte 
HOURS var byte 
DAY var byte 
DATE var byte 
MONTH var byte 
YEAR var byte 
CTRL var BYTE


SECS = 0
MINS = 30
HOURS = 12
DAY = 1
DATE = 1
MONTH = 1
YEAR = 09
CTRL = $90
PORTA.0 = 1
PORTA.1 = 1

LCDOUT $FE,1 



'lettura dell' ora
pause 500
skp:
I2CREAD SDA,SCL,$D0,$00,[SECS,MINS,HOURS,DAY,DATE,MONTH,YEAR,CTRL] 
pause 1000
LCDOUT $FE,$80,"T:",#SECS," ",#MINS," ",#HOURS," ",#CTRL,"       "
goto skp:
Back to top
Bjørn
Mon Nov 30 2009, 04:51PM
Bjørn Registered Member #27 Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
Did you remember a pull-up resistor on both data and clock?
Back to top
...
Mon Nov 30 2009, 09:11PM
... Registered Member #56 Joined: Thu Feb 09 2006, 05:02AM
Location: Southern Califorina, USA
Posts: 2445
You might also want to look at what data types are used by the ds1307, sometimes the little things like lsb first or msb first, two's compliment, etc, can throw you off.

Usually my system for interfacing a new part is to look for a register that has a known value (usually there is a device id or the likes) and looking at the value read back in binary--and then looking for the above issues.
Back to top
TheMerovingian
Tue Dec 01 2009, 01:01AM
TheMerovingian Registered Member #14 Joined: Thu Feb 02 2006, 01:04PM
Location: Prato/italy
Posts: 383
SOLVED!! It was two problems:

1) the I2CREAD/WRITE command must use variables instead of constants, it screws up the reading/writing
2) the data ins in BCD format (least significant bits are the units, bit4-6 the decade)

next step is to implement FAT SD writing and a workable interface


UPDATE:

Also it was the use of "analog" pull'up resistors in simulation that screwed up the things!
Back to top

Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Go to:

Powered by e107 Forum System
 
Legal Information
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.