Welcome, Guest
Username: Password: Secret Key Remember me

TOPIC: DS1307 troubles...

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

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
I got my 32.--- xtals today, so I finally got to plug my 1307 up!

I followed the example at:
http://digital-diy.com/Proton-Basic-Cod ... s1307.html

My other resources I have been using for this project is]


Device = 18F25K22



Declare Xtal 16



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 = %01110000;
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]







[proton filename=read clock.bas]


Device = 18F25K22



Declare Xtal 16



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 = %01110000;
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





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

All_Digital = true
PortB_Pullups = true




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


main]

BStop

' The DS1307 sends it data in BCD, therefore it must be changed to
' BIN so that it can be easily used (eg, print onto an LCD)

TempVal=Secs
GoSub BCD_TO_BIN
Secs=TempVal

TempVal=Mins
GoSub BCD_TO_BIN
Mins=TempVal

TempVal=Hrs
GoSub BCD_TO_BIN
Hrs=TempVal

TempVal=Date
GoSub BCD_TO_BIN
Date=TempVal

TempVal=Month
GoSub BCD_TO_BIN
Month=TempVal

TempVal=Year
GoSub BCD_TO_BIN
Year=TempVal





DelayMS 20


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

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


DelayMS 1000

GoTo main:



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


[/proton]

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

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
With my USB scope, I am NOT seeing any pulses on SDA or SLC, either. I should see some type of pulse for the request, even if the clock is not working and not seeing any response pulses.

That that tid-bit might be helpful.

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

  • be80be
  • be80be's Avatar
  • Offline
  • Senior Boarder
  • Posts: 79
  • Thanks received: 90
I got my 32.--- xtals today, so I finally got to plug my 1307 up!

What is that 32 khz or mhz if mhz you can't breadborad them

I guess 32.768 your code said 16mhz if your using a 32.768khz you may see something happen in about 4 to 5 hours

Change this OSCCON =%01110000; to this OSCCON =%01110010; and add this
OSCCON2 = %10000000;

And change this Declare Xtal 16 to Declare Xtal 64

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

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
Ive been working on this for 4 hours and give up for now... its midnight anyway.

I tried using i2cin and i2cout, and also hbstart and hbstop, even tried another chip from another supplier... nothing is working.

Everything appears to be "ok", but nothing.

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

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
32.xxx khz.

Ive got it on a breadboard now... it appeared to make contact okay.. Im all ears bud!

Andrew

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

  • RogerTango
  • RogerTango's Avatar
  • Offline
  • Fresh Boarder
  • Thanks received: 2
I soldered the legs of the xtal to the 1307 and put it back on the breadboard.

I reprogrammed the chip with the set and read hex files, still only get DEC "00" for all results.

Im going to bed for sure now....
Time to create page: 0.283 seconds