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 support@ccsinfo.com

I2C Silliness

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







I2C Silliness
PostPosted: Fri Feb 21, 2003 3:24 pm     Reply with quote

Ok, I'm about to throw my hands up on this one. I need another set of eyes/brains.

I've just finished a rather extensive project and before finalizing I was going to add the routine to talk to an external EEPROM (X4283 from Xicor) and it locks up when I try talking to it. I removed everything but the I2C routine and its still the same symptom; still stopping at the same point. I’ve got 10k pull-ups on the SDA and SCL lines.

It‘s sending out the start bit allright but just stops when it gets to the i2c_write(0xa0) part.

I know it’s probably something REAL stupid on my part because when I get stuck like this it means I’m too close to the problem and can’t see the big picture.

Here’s the bare code:

/*
Using CCS C Compiler v 3.061
*/

#include <16c773.h>

#fuses XT,NOWDT,NOBROWNOUT

#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3


#use delay(clock=4000000)
#use i2c(MASTER, SDA=EEPROM_SDA, SCL=EEPROM_SCL)


//--------------------- SUBROUTINES ------------------------

void init_ext_eeprom();
byte read_ext_eeprom(long address);


int Temp1;



main()
{
init_ext_eeprom();

Temp1=read_ext_eeprom(8);

}


//-------------------------- O --------------------------------
//---------------------- SUROUTINES ---------------------------
//-------------------------- O --------------------------------
byte read_ext_eeprom(long address)
{
byte data;
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
i2c_start();
i2c_write(0xa1); //Change data direction
data=i2c_read(0);
i2c_stop();
return(data);
}

void init_ext_eeprom()
{
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11982
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I2C Silliness
PostPosted: Fri Feb 21, 2003 3:36 pm     Reply with quote

:=I've just finished a rather extensive project and before finalizing I was going to add the routine to talk to an external EEPROM (X4283 from Xicor) and it locks up when I try talking to it. I removed everything but the I2C routine and its still the same symptom; still stopping at the same point. I’ve got 10k pull-ups on the SDA and SCL lines.
:=
:=It‘s sending out the start bit allright but just stops when it gets to the i2c_write(0xa0) part.
---------------------------------------------------------

I looked at the data sheet for the X4283. In the "Power On
Reset" section, it says for 200 ms after power-up, you can't
communicate with the EEPROM.

So modify your test program to put a 250 ms delay at the start
of main(). See if that helps.

Also, I didn't read the data sheet completely, but on that
same page, they say if SDA or SCL don't toggle within the
Watchdog timeout period, it asserts RESET and /RESET.
This apparently shuts down further i2c communications.
So it locks itself out ?
Anyway, this is an issue, and you'll have to research it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11984
Sergio
Guest







Re: I2C Silliness
PostPosted: Fri Feb 21, 2003 11:08 pm     Reply with quote

:=:=I've just finished a rather extensive project and before finalizing I was going to add the routine to talk to an external EEPROM (X4283 from Xicor) and it locks up when I try talking to it. I removed everything but the I2C routine and its still the same symptom; still stopping at the same point. I’ve got 10k pull-ups on the SDA and SCL lines.
:=:=
:=:=It‘s sending out the start bit allright but just stops when it gets to the i2c_write(0xa0) part.
:=---------------------------------------------------------
:=
:=I looked at the data sheet for the X4283. In the "Power On
:=Reset" section, it says for 200 ms after power-up, you can't
:=communicate with the EEPROM.
:=
:=So modify your test program to put a 250 ms delay at the start
:=of main(). See if that helps.
:=
:=Also, I didn't read the data sheet completely, but on that
:=same page, they say if SDA or SCL don't toggle within the
:=Watchdog timeout period, it asserts RESET and /RESET.
:=This apparently shuts down further i2c communications.
:=So it locks itself out ?
:=Anyway, this is an issue, and you'll have to research it.

Well, I had seen that but I thought it applied to the reset part of the chip only. The reset is sent as an outside signal from the chip. I don't believe that it resets the EEPROM chip or keeps it from functioning. It's meant to reset external circuitry.

The other thing that's throwing me off is that since the PIC is the master it should go ahead and try to communicate with the chip. At least until the first ack from the eeprom chip. In other words, should I not see the clock signal go up and down as it tries to communicate with it?

It seems to send a valid start to the eeprom chip (looking at both lines with the scope) but stops right after, as soon as it tries to send it the slave address. If the trouble was the eeprom chip should I not see the PIC send those bits to the eeprom anyway? I would not see an ack from the eeprom but I would expect to see the I2C_write routine to finish. It never begins.

I will put in a wait routine in case.

Thanks for the quick response.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11992
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: I2C Silliness
PostPosted: Fri Feb 21, 2003 11:44 pm     Reply with quote

Look at the data line. If the master tries and transmit a 1 (high) and the signal is 0 (low) the master loses arbitration and stops transmitting.


:=:=:=I've just finished a rather extensive project and before finalizing I was going to add the routine to talk to an external EEPROM (X4283 from Xicor) and it locks up when I try talking to it. I removed everything but the I2C routine and its still the same symptom; still stopping at the same point. I’ve got 10k pull-ups on the SDA and SCL lines.
:=:=:=
:=:=:=It‘s sending out the start bit allright but just stops when it gets to the i2c_write(0xa0) part.
:=:=---------------------------------------------------------
:=:=
:=:=I looked at the data sheet for the X4283. In the "Power On
:=:=Reset" section, it says for 200 ms after power-up, you can't
:=:=communicate with the EEPROM.
:=:=
:=:=So modify your test program to put a 250 ms delay at the start
:=:=of main(). See if that helps.
:=:=
:=:=Also, I didn't read the data sheet completely, but on that
:=:=same page, they say if SDA or SCL don't toggle within the
:=:=Watchdog timeout period, it asserts RESET and /RESET.
:=:=This apparently shuts down further i2c communications.
:=:=So it locks itself out ?
:=:=Anyway, this is an issue, and you'll have to research it.
:=
:=Well, I had seen that but I thought it applied to the reset part of the chip only. The reset is sent as an outside signal from the chip. I don't believe that it resets the EEPROM chip or keeps it from functioning. It's meant to reset external circuitry.
:=
:=The other thing that's throwing me off is that since the PIC is the master it should go ahead and try to communicate with the chip. At least until the first ack from the eeprom chip. In other words, should I not see the clock signal go up and down as it tries to communicate with it?
:=
:=It seems to send a valid start to the eeprom chip (looking at both lines with the scope) but stops right after, as soon as it tries to send it the slave address. If the trouble was the eeprom chip should I not see the PIC send those bits to the eeprom anyway? I would not see an ack from the eeprom but I would expect to see the I2C_write routine to finish. It never begins.
:=
:=I will put in a wait routine in case.
:=
:=Thanks for the quick response.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11993
Jean-Louis VERN
Guest







Re: I2C Silliness
PostPosted: Sat Feb 22, 2003 8:57 am     Reply with quote

:=Ok, I'm about to throw my hands up on this one. I need another set of eyes/brains.
:=
:=I've just finished a rather extensive project and before finalizing I was going to add the routine to talk to an external EEPROM (X4283 from Xicor) and it locks up when I try talking to it. I removed everything but the I2C routine and its still the same symptom; still stopping at the same point. I’ve got 10k pull-ups on the SDA and SCL lines.
:=
:=It‘s sending out the start bit allright but just stops when it gets to the i2c_write(0xa0) part.
:=
:=I know it’s probably something REAL stupid on my part because when I get stuck like this it means I’m too close to the problem and can’t see the big picture.
:=
:=Here’s the bare code:
:=
:=/*
:= Using CCS C Compiler v 3.061
:=*/
:=
:=#include <16c773.h>
:=
:=#fuses XT,NOWDT,NOBROWNOUT
:=
:=#define EEPROM_SDA PIN_C4
:=#define EEPROM_SCL PIN_C3
:=
:=
:=#use delay(clock=4000000)
:=#use i2c(MASTER, SDA=EEPROM_SDA, SCL=EEPROM_SCL)
:=
:=
:=//--------------------- SUBROUTINES ------------------------
:=
:=void init_ext_eeprom();
:=byte read_ext_eeprom(long address);
:=
:=
:=int Temp1;
:=
:=
:=
:=main()
:= {
:= init_ext_eeprom();
:=
:= Temp1=read_ext_eeprom(8);
:=
:= }
:=
:=
:=//-------------------------- O --------------------------------
:=//---------------------- SUROUTINES ---------------------------
:=//-------------------------- O --------------------------------
:=byte read_ext_eeprom(long address)
:= {
:= byte data;
:= i2c_start();
:= i2c_write(0xa0);
:= i2c_write(address>>8);
:= i2c_write(address);
:= i2c_start();
:= i2c_write(0xa1); //Change data direction
:= data=i2c_read(0);
:= i2c_stop();
:= return(data);
:= }
:=
:=void init_ext_eeprom()
:= {
:= output_float(EEPROM_SCL);
:= output_float(EEPROM_SDA);
:= }
___________________________
This message was ported from CCS's old forum
Original Post ID: 11997
Jean-Louis VERN
Guest







Re: I2C Silliness
PostPosted: Sat Feb 22, 2003 8:58 am     Reply with quote

I think that the 10k pullup resistor is too high (you need a rising edge < 1us)... try with 1k...
___________________________
This message was ported from CCS's old forum
Original Post ID: 11998
Sergio
Guest







Re: I2C Silliness......... Found my problem!!
PostPosted: Sun Feb 23, 2003 5:17 pm     Reply with quote

Ok, I found the problem. And I’ll post my method of tackling it. It turned out to be applicable to my particular situation. Even though I thought it was pointing towards a CCS bug I waited till I had more info before making any accusations (CCS flamers take notice).

What was throwing me off was that it would send the start bits (SCL and SDA data lines) correctly but would just stop after that. I knew that the PIC being the master and only transmitting that it should send the address no matter what.. even if I took the EEPROM chip out.

I had been developing this device with my emulator (Mathias) and when I would single-step it, it would always stop at the I2C routine after the start routine. I whittled it down to either my emulator or a CCS bug. I burned a chip and put it in the board and, lo and behold, it worked just fine, the SDA and SCL signals both nice and clean and was not stopping after the start signal. I began looking at the “use I2C” routines and found the problem.

The board I’m designing is a 3 volt board (battery powered so I had to conserve as much juice as I could) and my emulator only runs at 5 volts. This was no problem as long as I had that in the back of my head when designing the interfaces and when switching between the emulator and the chip.

Well, my pull-ups were tied to the 3-volt line. To see a “1” my emulator needs at least a .7X Voltage which at 5 volts would be 3.5 volts. In other words it would try to send out a “1” but the voltage was not high enough. I believe rhe CCS routine does check to make sure that it was sending the “1”. Since it couldn’t see it, it would stop.

Mark:
You were going in the right direction. I haven’t looked at the assembly code in detail but it obviously does check to see if it’s sending the right signal.

PCM Programmer:
I almost sent the message to you personally. Since you’re so familiar with CCS if there were a bug in that area you’d know about it. I’m glad you were the first to respond.

Thanks guys, this forum is very nice to have.

Sergio
___________________________
This message was ported from CCS's old forum
Original Post ID: 12042
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