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

Hardware I2C problem

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



Joined: 28 Apr 2004
Posts: 14

View user's profile Send private message

Hardware I2C problem
PostPosted: Mon Sep 17, 2007 7:05 am     Reply with quote

Hi to All !

I have a problem with the I2c on a Pic 18F2680.
I set the I2C with the following line:

#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,force_hw)

I Have to use the "force_hw" because I have to use the i2c_poll() instruction.

But when i call the i2c_write() the PIC seems to stop the execution of program.

For example in the above code I see only the first "printf" line:


i2c_start();
printf("Get_LM_92_Temperature_BD1\n\r");
if (i2c_write(LM_92_ADR_READ)!= 1)
{
printf("Get_LM_92_Temperature_BD2\n\r");
i2c_stop();
return(false);
}
printf("Get_LM_92_Temperature_BD3\n\r");


I search in to the CCS forum and I tried , like some topic advice, to set up the C4 and C3
like input , but the PIC still stop the execution.

I compile my source code with PCMH Ver 3.249.

How can I resolve this question ?

Thanks
Ttelmah
Guest







PostPosted: Mon Sep 17, 2007 8:15 am     Reply with quote

A couple of obvious comments:
1) You have got the pull up resistors on the I2C bus?.
2) How are the A0/A1 lines on the LM92 wired?.
3) What is the value of 'LM_92_ADR_READ'?.

Best Wishes
Inkwaterman



Joined: 28 Apr 2004
Posts: 14

View user's profile Send private message

PostPosted: Mon Sep 17, 2007 8:54 am     Reply with quote

Hi !

Quote:

A couple of obvious comments:
1) You have got the pull up resistors on the I2C bus?.
2) How are the A0/A1 lines on the LM92 wired?.
3) What is the value of 'LM_92_ADR_READ'?.


1) Yes I have.
2) Both A1 and A0 il pulled Down.
3) #define LM_92_ADR_READ 0x90.

Another question:

If I have no devices on my I2C line and I call i2c_write() function what's happen ?

Supposed my I2C slave is damaged, what's the return value of i2c_write() function ?


thanks
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Sep 17, 2007 10:20 am     Reply with quote

First, you need to establish if the LM92 is talking to the I2C bus. Try something like this:

Code:
i2c_start();
if(!i2c_write(0x90))// send sensor's address and look for an ACK
{
  printf("ACK'd\n\r");
}
else
{
  printf("NOACK\n\r");
}
i2c_stop();


This is simple but should establish if the sensor is talking or not. If there is nothing connected to the bus then there should be no ACK and the program should continue on it's way.

You might want to try this with and without the FORCE_HW option. I've had instances when the FORCE_HW caused problems with my Master.

The sensor(Slave) does have the ability to 'hold' the bus as 'busy' and the master will wait until it is released. If I remember correctly, it's the SCL line that is held low by the slave. This is a feature that enables the slave to have the time to do whatever it needs to before the master starts sending more commands to it. If you have a scope you can look at the signals to see what's going on. A scope is a huge asset when debugging things of this nature.

If there's no device on the bus or if the device refuses to answer, the returned value should be 0xFF since the data line is being held high with the pull-ups. In this case there will be a NOACK returned as well.

Good luck!

Ronald
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