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

problem. pic reboots

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



Joined: 26 Apr 2006
Posts: 38
Location: Portugal

View user's profile Send private message

problem. pic reboots
PostPosted: Fri Sep 08, 2006 5:34 pm     Reply with quote

Hi forum!

i am working with 2 PIC18F4525, being one the master i2c, and the other of course is the slave.

i am using ccs V3.235, in MPlab v7.40.

i have some problems with the implementation of the multi-byte send/receive code. i am using some interrupts. the problem is that the master from time to time reboots, and the i2c freezes.

here is some of my code

Master:
Code:


/* definicao do oscilador externo do microcontrolador */
#use delay(clock=10000000)


#fuses NOWDT,HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT//, NOXINST

/* configuracao de porta RS-232 (comunicacao serie) */
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7)

#int_timer1     // interrup��o a cada 5,5s
void tempo_sage()
{
   static int conta;

   set_timer1(3036+get_timer1());
   
   conta++;
   if(conta==25)
   {
      conta=0;
       le_hora();
      envia_datahora();
       info = recebe_dados();
   }

}


the function
Code:
le_hora();
read time and date from RTC
the function
Code:
envia_datahora();
sends data to slave
the function
Code:
recebe_dados();
receives data from slave

usually the program freezes in the receive function, after sending adress.
here is the code for receive:
Code:

void recebe_dados()
{
   
      delay_cycles(10);
      i2c_start();
      i2c_write(SLAVE_ADDRESS+1);
      for(e=0;e<13;e++)
   {
        delay_us( 60 );
      in_buffer[e] = i2c_read(1);
      printf("\r\nin_buffer[%d] =  %d ",e, in_buffer[e]);
   }

   
                delay_us( 60 );
   in_buffer[13] = i2c_read(0);
   printf("\r\nin_buffer[13] =  %d ",in_buffer[13]);
   delay_ms( 10 );
   i2c_stop();   
}




well, this is it.
can someone gimme a tip?

thnak you a lot
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 08, 2006 9:42 pm     Reply with quote

Quote:
The problem is that the master from time to time reboots, and the i2c freezes.

You have a very large amount of code in your interrupt routine.
That's not a recommended programming method.

In addition to that, read the following threads. Check if you're doing
any of the things listed in these threads:
http://www.ccsinfo.com/forum/viewtopic.php?t=26793
http://www.ccsinfo.com/forum/viewtopic.php?t=24548&start=21
http://www.ccsinfo.com/forum/viewtopic.php?t=25903
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