cjusto
Joined: 26 Apr 2006 Posts: 38 Location: Portugal
|
problem. pic reboots |
Posted: Fri Sep 08, 2006 5:34 pm |
|
|
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 read time and date from RTC
the function sends data to slave
the function 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 |
|