Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: DS1307 troubles...

Re: DS1307 troubles... 8 years 2 months ago #8527

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
Should mention too, I scoped all the pins, I cant find any hint of I2C pulses. However, my serial LCD looks very nice on the scope....

Re: DS1307 troubles... 8 years 2 months ago #8528

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
I re-read your reply... the 32.xxkhz xtal is for the DS1307, thats where its connected. The PIC is running at 16mhz internal osc right now (I disabled PLL even...)

HTH
Andrew

Re: DS1307 troubles... 8 years 2 months ago #8529

  • be80be
  • be80be's Avatar
  • Offline
  • Senior Boarder
  • Posts: 79
  • Thanks received: 90
Try this
Device = 18F25K22



Declare Xtal 64



Config_Start
MCLRE = INTMCLR ; RE3 input pin enabled; MCLR disabled
FOSC = INTIO67 ; Internal oscillator block, port function on RA6 and RA7
PLLCFG = On ; Oscillator multiplied by 4

Config_End



OSCCON =%01110010;
OSCCON2 = %10000000;
OSCTUNE = %00100000;





SerOut PORTC.4 , 84 , [$fe,$0c]
DelayMS 50



Dim Temp1 As Byte
Dim Temp2 As Byte
Dim TempVal As Byte

Dim Secs As Byte
Dim Mins As Byte
Dim Hrs As Byte
Dim day As Byte
Dim Date As Byte
Dim Month As Byte
Dim Year As Byte
Dim Ctrl As Byte

Dim Secs_last As Byte



Dim x As Word



' Define I2C bus ports
'declare SDA_Pin = PORTC.3 'DS1307 SDA pin
'declare SCL_Pin =PORTC.2 'DS1307 SCL pin

All_Digital = true
PortB_Pullups = true


' Set initial DS1307 time / Date

Secs = 0 ' Set seconds
Mins = 37 ' Set minutes
Hrs = 7 ' Set hours

day = 7 ' Set day of week value

Date = 9 ' Day of month value
Month = 7 ' Month value
Year = 11 ' Year value

Ctrl = 0 ' Set the control byte (leave as 0 in this example)



' The DS1307 works with data in BCD format, so convert BIN to BCD

TempVal=Secs
GoSub BIN_TO_BCD
Secs=TempVal

TempVal=Mins
GoSub BIN_TO_BCD
Mins=TempVal

TempVal=Hrs
GoSub BIN_TO_BCD
Hrs=TempVal

TempVal=day
GoSub BIN_TO_BCD
day=TempVal

TempVal=Date
GoSub BIN_TO_BCD
Date=TempVal

TempVal=Month
GoSub BIN_TO_BCD
Month=TempVal

TempVal=Year
GoSub BIN_TO_BCD
Year=TempVal


For x = 1 To 5
DelayMS 1000

' The datasheet specifies the first byte is 1101000x where x is read(1) or write(0).
' The second byte tells the DS 1307 where to start reading, 0 is at the start.
' The Ctrl byte contains advanced features, read the datasheet for more info
BusOut 11010000, 0, [Secs, Mins, Hrs, day, Date, Month, Year, Ctrl]
'Write initial values for time / Date

BStop

DelayMS 20


SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10
SerOut PORTC.4 , 84 , ["Time Programmed"]
DelayMS 1000

Next x

SerOut PORTC.4 , 84 , [$fe,1]
DelayMS 10
SerOut PORTC.4 , 84 , ["Program Finished"]



End




BCD_TO_BIN: ' Convert the BCD values into BIN

Temp1 = $0F & TempVal ' Clear off the top four bits
Temp1 = Dig Temp1, 0
Temp2 = TempVal >> 4 ' Shift down four to read 2 BCD value
Temp2 = Dig Temp2, 0
TempVal = Temp2 * 10 + Temp1

Return

BIN_TO_BCD:

Temp1 = Dig TempVal, 0 ' GET THE DEC DIGIT FOR THE FIRST NIBBLE
Temp2 = Dig TempVal, 1 ' GET THE DEC DIGIT FOR THE FIRST NIBBLE
Temp2 = Temp2 << 4 ' MOVE NUMBER OVER TO 2ND NIBBLE

' XOR THEM TOGTHER TO MAKE THE WHOLE BCD NUMBER
TempVal = Temp1 ^ Temp2

Return

Re: DS1307 troubles... 8 years 2 months ago #8530

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
Change this OSCCON =%01110000; to this OSCCON =%01110010; and add this
OSCCON2 = %10000000;

And change this Declare Xtal 16 to Declare Xtal 64

For clarity, that is setting it to run 64mhz internal osc with pll, correct?
I wanted to be sure of your intention before I go to the datasheet.

Andrew

Re: DS1307 troubles... 8 years 2 months ago #8531

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
I tried your code, something must be ajar... my LCD only displays random chars..
Somewhere the 9600bps is getting askew.

Thanks for your time in helping...

I just got done today getting my DS18B20 working, it was easy with the tutorial that was posted. Sorry, that was a side thought. HA HA!

Be cool bro, Ill check back tomorrow and see if you see anything.

Oh, BTW, there was a missing BSTART in the set time code I originally posted, that had been corrected just after posting the code.

Andrew

Re: DS1307 troubles... 8 years 2 months ago #8532

  • Jon Chandler
  • Jon Chandler's Avatar
  • Offline
  • Moderator
  • Posts: 365
  • Thanks received: 352
Do you have 4.7k pullup resistors from SDA and SCL to +5V? The I2C lines are open collector, meaning they can only pull the lines low - without the pullup resistors, the lines will never be high.

If you're seeing nothing on the lines with a 'scope and they're at 0, this is almost certainly the problem.
The following user(s) said Thank You: hop
Time to create page: 0.255 seconds