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

SDA line low

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



Joined: 20 Oct 2006
Posts: 1

View user's profile Send private message

SDA line low
PostPosted: Fri Oct 20, 2006 4:26 am     Reply with quote

Hello,
I'm using a PIC18F6722 in I2C master mode and PIC16F2520, TCN35, DS1339 and a EEPROM(24FC512) in a slave mode.
The problem is that to the end of some time, the program of the PIC18F6722 crash, and reset always by watchdog of minute to minute. When I'm going to see the line of SDA, this is low all the time. Why??? What can provoke this?

Code for 18F6722

#include <18F6722.h>
#fuses EC_IO, NOBROWNOUT, WDT16384, NOPUT, NOSTVREN, NODEBUG, PROTECT, PUT, LVP
#use delay(clock=20000000)
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, errors, stream=USART_A)
#use rs232(baud=9600, parity=N, xmit=PIN_G1, rcv=PIN_G2, bits=8, errors, stream=USART_B)
#use rs232(baud=19200, parity=N, xmit=PIN_C0, rcv=PIN_B1, bits=8, stream=USART_C)
#use i2c(Master, SLOW, sda=PIN_C4, scl=PIN_C3)

//some functions of read and write in I2C

//for 18F2520
void Read_GPS(unsigned int8 CMD)
{
char reg_gps[PIC_GPS_LENTGH_REG];
unsigned int8 i;
boolean GPS_OK,flag=true;

do {
delay_ms(PIC_GPS_TIME_WRITE);//5ms
i2c_start();
i2c_write(PIC_GPS_ADDRESS | PIC_GPS_WRITE);
delay_ms(PIC_GPS_START_TIME_WRITE);
i2c_write(CMD);
delay_ms(PIC_GPS_TIME_WRITE);
i2c_start();
i2c_write(PIC_GPS_ADDRESS | PIC_GPS_READ);
delay_ms(PIC_GPS_TIME_WRITE);
switch (CMD)
{
case READ_PIC_GPS_ALR:
for (i=0;i<PIC_GPS_LENTGH_ALR-1;i++)
{
reg_gps[CMD+i]=i2c_read(1);
delay_ms(PIC_GPS_TIME_READ);
}
reg_gps[CMD+i]=i2c_read(0);
i2c_stop();
Processar_Alarmes(reg_gps);
GPS_OK=true;
break;
case READ_PIC_GPS_LOC:
for (i=0;i<PIC_GPS_LENTGH_LOC-1;i++)
{
reg_gps[CMD+i]=i2c_read(1);
delay_ms(PIC_GPS_TIME_READ);
}
reg_gps[CMD+i]=i2c_read(0);
i2c_stop();
GPS_OK=Processar_Localizacao(reg_gps);
break;
case READ_PIC_GPS_VER_FW:
for (i=0;i<PIC_GPS_LENTGH_VER_FW_REV_ID-1;i++)
{
reg_gps[CMD+i]=i2c_read(1);
delay_ms(PIC_GPS_TIME_READ);
}
reg_gps[CMD+i]=i2c_read(0);
i2c_stop();
GPS_OK=Processar_Versoes(reg_gps);
break;
}
}

//for 16F2520
void Write_GPS(unsigned int8 CMD, char STR[], unsigned int8 LENGTH)
{
unsigned int8 i;

delay_ms(PIC_GPS_TIME_WRITE);
i2c_start();
i2c_write(PIC_GPS_ADDRESS | PIC_GPS_WRITE);
delay_ms(PIC_GPS_START_TIME_WRITE);
i2c_write(CMD);
for (i=0;i<LENGTH>> 16);
i2c_start();
i2c_write(EEXC51X | (chip<<1>> 8));
i2c_write((int8)(ADRESS & 0x000000FF));
i2c_write(DADO);
i2c_stop();
output_high(DEC_CS0);
delay_ms(5);
}

//for 24FC512
unsigned int8 read_24xc51x(unsigned int32 ADRESS)
{
unsigned int8 chip,DADO;

#ifdef __24XC515
if (bit_test(ADRESS,15))
bit_set(ADRESS,18);
else
bit_clear(ADRESS,18);
#endif
chip=(int8)(ADRESS >> 16);
i2c_start();
i2c_write(EEXC51X | (chip<<1>> 8));
i2c_write((int8)(ADRESS & 0x000000FF));
i2c_start();
i2c_write(EEXC51X | (chip<<1) | EEREAD);
DADO=i2c_read(0);
i2c_stop();
delay_us(5);
return DADO;
}

//forDS1339
void write_rtc(unsigned int8 REGISTO, unsigned int8 VALOR)
{
i2c_start();
i2c_write(ADR_RTC | RTC_WRITE);
i2c_write(REGISTO);
i2c_write(VALOR);
i2c_stop();
}

//forDS1339
unsigned int8 read_rtc(unsigned int8 REGISTO, boolean MODO)
{
unsigned int8 time=0;

delay_us(4);
i2c_start();
i2c_write(ADR_RTC | RTC_WRITE);
i2c_write(REGISTO);
i2c_start();
i2c_write(ADR_RTC | RTC_READ);
time=i2c_read(0);
i2c_stop();
return time;
}


//for TCN75
int16 th_read(byte ADDR_CHIP)
{
int8 th1=0;
int8 th2=0;
int16 th=0;

i2c_start();
i2c_write((TCN75_ADDR | ADDR_CHIP | TCN75_WRITE));
i2c_write(TCN75_TEMP);
i2c_start();
i2c_write((TCN75_ADDR | ADDR_CHIP | TCN75_READ));
th1=i2c_read(1);
th2=i2c_read(0);
i2c_stop();
if (bit_test(th1,7))
{
th1=th1-1;
th1=~th1;
bit_set(th1,7);
}
th=th1;
th=((th<<8) | th2);
return th;
}

//For TCN75
void th_escreve_config(byte ADDR_CHIP, byte CONFIG)
{
i2c_start();
i2c_write((TCN75_ADDR | ADDR_CHIP | TCN75_WRITE));
i2c_write(TCN75_PRCONF);
i2c_write(CONFIG);
i2c_stop();
}




Note: I need to put delays between all the i2c functions(i2c_start, i2c_read, i2c_write and i2c_stop)??

Thanks[/list]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 20, 2006 11:46 am     Reply with quote

Quote:
The problem is that to the end of some time, the program of the
PIC18F6722 crash, and reset always by watchdog of minute to minute.
When I'm going to see the line of SDA, this is low all the time. Why???
What can provoke this?

Quote:

#include <18F6722.h>
#fuses EC_IO, NOBROWNOUT, WDT16384, NOPUT, NOSTVREN, NODEBUG, PROTECT, PUT, LVP

I didn't look at your code in detail, but the LVP fuse could cause
random lock-ups, unless you have a pull-down resistor on the PGM pin.

That's a hardware reason. A very common software reason for
random crashes, is if you are accidently writing beyond the end of
an array. You could destroy the contents of other variables that way.

See this thread for some links that discuss reasons for random resets
and lock-ups.
http://www.ccsinfo.com/forum/viewtopic.php?t=27638&start=4
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