View previous topic :: View next topic |
Author |
Message |
Inkwaterman
Joined: 28 Apr 2004 Posts: 14
|
Hardware I2C problem |
Posted: Mon Sep 17, 2007 7:05 am |
|
|
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
|
|
Posted: Mon Sep 17, 2007 8:15 am |
|
|
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
|
|
Posted: Mon Sep 17, 2007 8:54 am |
|
|
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
|
|
Posted: Mon Sep 17, 2007 10:20 am |
|
|
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 |
|
|
|