View previous topic :: View next topic |
Author |
Message |
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
i2c hangup |
Posted: Fri Aug 25, 2017 8:26 am |
|
|
I have a pic that has an i2c Master connection to a single i2c slave chip on a separate pcb. It has been working fine. But if I disconnect the i2c the program hangs. I don't understand from the manual & datasheet why that would happen. The PIC is a Master and it should just toggle the lines and return the ACK status without hanging. Am I missing something obvious here?
Here are my #use setups.
I added some i2c lines below to the beginning of my code and it hangs it up every time. Using either the read or write command causes the hang. I'm going to break out the scope and see what the lines are actually doing. Maybe that will give me a clue.
PIC: 18F67K40
CCS: V5.074
MPLAB X v3.65
setup:
Code: |
#use RS232(UART1,Baud=19200,PARITY=N,BITS=8,ERRORS)
#use i2c(I2C2, master,FAST=200000)
// test if I2C lines are floating and not tied to gnd
if((input(i2c_SDA2) == 0) || (input(i2c_SCK2) == 0)){
printf("\r\n FAULT: I2C bus line held low! press any key...");
getch();
} else{
printf("\r\n I2C bus lines floating hi - okay");
}
i2c_start();
//i2c_read();
i2c_write(0xa0);
i2c_stop();
printf("\r\n Never prints this line");
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Aug 25, 2017 8:49 am |
|
|
Look at PCM_programmers I2C bus scanner program in the code library.
This shows how to scan a bus and see if a device is there.
Must admit from what you post, it should reach the print line. Are you sure your line definitions are right?. What is attached?. If your device holds the clock line low when addressed, this would cause a problem.... |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Fri Aug 25, 2017 9:35 am |
|
|
My definitions should be okay because it seems to work fine as long as the chip is connected. The problem is when nothing is attached at all - the i2c...arg! I just realized something. It's a customer design and the pullups for the i2c are on the remote board! So the i2c lines are literally floating with nothing connected. I'll bet that's somehow the problem.
Sometimes just explaining the problem to someone helps a lot! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Fri Aug 25, 2017 10:15 am |
|
|
oopsy ! yup, floating I2C lines are a big 'NONO'...
..just don't as HOW I know that.....
bottom line .. the master should have pullups, even jumper selectable if need be.
Jay |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Fri Aug 25, 2017 10:33 am |
|
|
Understood.
At least it wasn't MY hardware design. I can always say I'd never had done that, LOL. But I'm sure there will be a rev, so I'll put in a request.
Sorry to have bothered you on such a bonehead thing, but at least you got a good laugh on a Friday!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Aug 25, 2017 11:54 am |
|
|
The key one is the clock line. If this is seen as 'low' after a write, the chip will think the I2C is being held low by the other device. |
|
|
|