CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

strange errors with the combination ds1307 + rs232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pattousai



Joined: 23 Aug 2006
Posts: 37

View user's profile Send private message

strange errors with the combination ds1307 + rs232
PostPosted: Wed Oct 15, 2008 8:08 pm     Reply with quote

Hi everybody,

Well, I'm developing a circuit that uses 2 rs232 and a ds1307, and all of a suddenly the program started to behave strangely. I could localize (I guess) the source of my problem, and is shown in the little code below.

Code:

#include <18f2525.h>
#fuses HS, NOWDT, NOLVP, NOMCLR, NOBROWNOUT, NOPUT
#use delay(clock=24000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <ds1307.c>

/* variables declaration */

#int_ext2
void interrupcao_ext2()
{
   flag_rtc = true;
}

void main()
{   
   enable_interrupts( INT_EXT2 );
   enable_interrupts( GLOBAL );   
   
   ds1307_init();
 
   ds1307_set_date_time(11,10,8,6,23,38,00);
     
   printf( "Starting the program\r\n" );
   
   while( 1 ){   
      if( flag_rtc ){
         ds1307_get_date(day,month,year,dow);
         ds1307_get_time(hour,min,sec);
         
         printf("RTC: \%02d:\%02d:\%02d\r\n", hour, min, sec);
         
         flag_rtc = false;
      }     
   } 
}


The problem is that the 'printf("Starting the program\r\n")' always prints garbage. If I put it inside the 'if( flag_rtc )', it also prints garbage. What is interesting is that the 'printf("RTC: ...")' prints ok (except that sometimes prints wrong values, like "RTC: 45:45:85", but the problem is with the ds1307 circuit, I guess).

I also test a very simple code, like
Code:

while(1){
   delay_ms(1000);
   printf("testing\r\n");
}


but keeping the same circuit (with the ds1307 connected to the pic), and the problem continues. Which makes me think that the problem is something about the pullup resistors... but I don't know what to do, I already test with 2k6, 4k7, 5k6 and 10k, all gives me the same thing :S

Well, more details about my circuit: i'm using a battery of 3,6V in series with a diode (gives me around of 3,2V) in the Vbat pin of the ds1307, i already try some pullup resistors (like i said before), i'm using a 32,768kHz crystal connected to the ds1307 without any load capacitors (when i put them the ds1307 goes slow, and without its counting ok) and my power source is a voltage regulator 7805 with a 1000uF and a 100nF in parallel and connecting the Vout to the ground and a 330nF connecting the Vin to the ground. But my regulator is giving me a 4,6 to 4,7V, which is a very dangerous voltage, because the ds1307 need a 4,5V to enable reading and writing (i guess that is the problem when i read wrong values, the voltage goes under 4,5V and then i can't read from the ds1307), but this configuration of capacitors is exactly the same of the datasheet (to be true, in the datasheet it hasn't the 1000uF, but i already try without them).

My compiler version is the 4.057... and... i guess this is it. So... i'm accepting suggestions on how to make the printf works with the ds1307 and to make my regulator more accurate.


Thanks very much for reading all this stuff and sorry for the bad english.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 15, 2008 10:12 pm     Reply with quote

1. Fix the regulator problem.

2. Remove all interrupt code and make the DS1307 work first.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Oct 15, 2008 10:34 pm     Reply with quote

Sound like you are receiving spurious interrupts.

Make sure you have a pull-up resistor on SQW/OUT pin of the DS1307 (open drain output).

You do not need capacitor on the crystal for the DS1307. It has built in 12.5pF on these pins.

The DS1307 is very fussy about VDD, it must not fall below the voltage on the VBatt terminal
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group