View previous topic :: View next topic |
Author |
Message |
aasanchez
Joined: 17 May 2013 Posts: 8
|
DS1307, send me bad values.... |
Posted: Tue Jul 02, 2013 2:40 pm |
|
|
Hi, greetings, now i have a problem please if you could help me, this gonna be wonderful.
I trying use a DS1307 clock, and i use this lib: http://www.ccsinfo.com/forum/viewtopic.php?t=23255 but in the serial port monitor, (included in this compiler, this is the result
Code: |
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
|
Obviously this values are wrong, but i cant find the error... please could you help me
This is the code:
Code: |
#include <18F4520.h>
#FUSES HS
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT
#FUSES NOLVP //No low voltage programing
#use delay (clock=20000000) //Fosc=20Mhz
//Configuracion RS232
#use fixed_io(c_outputs=PIN_C6)
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=RS232)
#include <ds1307.c>
void main(){
BYTE sec;
BYTE min;
BYTE hrs;
ds1307_init();
//Set date for->15 June 2005 Tuesday
//Set time for->15:20:55
ds1307_set_date_time(15,6,5,2,15,20,55);
while(TRUE){
delay_ms(1000);
ds1307_get_time(hrs,min,sec);
printf("%d %d %d",hrs,min,sec);
printf("\r\n");
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Jul 02, 2013 5:29 pm |
|
|
hardware...
do you have the correct I2C bus pullup resistors ? typically 3k3r or 4k7r will work.
do you have a battery connected to the DS1307 ? it's needed for proper operation
hth
jay |
|
|
aasanchez
Joined: 17 May 2013 Posts: 8
|
|
Posted: Tue Jul 02, 2013 5:43 pm |
|
|
No have battery, and resitors is 4k7... Thanks a lot... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Jul 02, 2013 7:25 pm |
|
|
hmmm.. just noticed you've used 'fixed_io'...
I'd remove that,recompile, and see what happens.
Normally, for 99.999999% of the programs ever seen here, you do NOT need to use fixed_io. Let the compiler handle the 'details' as it sees to.
Unless you need really tight, fast code( not needed here...) using 'fast_io' an cause you 'problems'.
hth
jay |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Jul 03, 2013 12:41 am |
|
|
aasanchez wrote: | No have battery, and resitors is 4k7... Thanks a lot... |
The DS1307 will not work correctly or reliably with the battery terminal floating (no battery or unconnected battery). During development this can be easily fixed using either a pull up resistor or pull down resistor - it does not matter which. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
fatalyric
Joined: 21 Aug 2013 Posts: 2
|
Re: DS1307, send me bad values.... |
Posted: Wed Aug 21, 2013 1:13 pm |
|
|
aasanchez wrote: | Hi, greetings, now i have a problem please if you could help me, this gonna be wonderful.
Code: |
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
45 85 85
|
|
I have this problem :( Need help pls (I use 18f4580, SDA=B5 SCL=B6 ===> I edited ds1307.c ) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 21, 2013 1:20 pm |
|
|
1. Don't use pins B6 or B7 for i2c. They are used by the ICD debugger/programmer.
2. Make sure you have a 3 volt battery connected to the Vbat pin. |
|
|
fatalyric
Joined: 21 Aug 2013 Posts: 2
|
|
Posted: Fri Aug 23, 2013 9:31 am |
|
|
PCM programmer wrote: | 1. Don't use pins B6 or B7 for i2c. They are used by the ICD debugger/programmer.
2. Make sure you have a 3 volt battery connected to the Vbat pin. |
I hate I2C, ahahaha
proteus simulator work fine , but real is
45 85 85
45 85 85
45 85 85
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Fri Aug 23, 2013 9:37 am |
|
|
The real problem is that Proteus is NOT working according to the REAL hardware! We all know Proteus is full of bugs, erros, faulty DRCs...
The numbers you show us, tell us, that you do not have a 3 volt battery connected to the DS1307. The datasheet clearly states you MUST have one connected in order for the RTC to function properly.
I've used 1307s for years, have hundreds in the real world, all work fine.
If you still have problems then post your schematic as well as a picture of the hardware setup.
hth
jay |
|
|
|