View previous topic :: View next topic |
Author |
Message |
jenipapo
Joined: 27 Jan 2008 Posts: 4 Location: France
|
i2c slave scl and sda stick to gnd |
Posted: Mon Aug 09, 2010 8:06 am |
|
|
Hi, all
I try to use slave i2c routines on a 18F2420.
Time to time, I can see SCL and SDA lines stuck to gnd.
Their level become "normal" only after a power OFF/ON.
Here you can find i2c interrupt routine:
Code: |
#INT_SSP
void spp_interrupt() {
BYTE incoming = 0;
BYTE state = 0;
BYTE byindex = 0;
static BYTE address = 0;
// on lit l'état de l'automate i2c hardware
state = i2c_isr_state();
// ???
I2CSTATE = state;
// master is writing
if(state < 0x80) {
// we read it
incoming = i2c_read();
// its an address
if(state == 1) {
// address limiattion
address = incoming & 0b00001111;
}
// master is writing data
if(state == 2) {
// we save it
abyBufferI2c[address] = incoming;
}
}
// master wants to read
if(state == 0x80) {
// si index == 0 on locke, si index == 3 on délocke ???
if(address == 0) {
// ???byLockOdo = LOCK_ON;
}
// we send requested data to master(index) préalablement reçue
i2c_write(abyBufferI2c[address]);
// ??? déblocage manuel du clock
CKP=1;
if(address == 3) {
byLockOdo = LOCK_OFF;
}
}
// le maitre demande une lecture (cas de l'autoincrément)
if(state > 0x80) {
// on extrait la valeur de l'adresse (index) et on limite sa valeur à 16
byindex = (state - 0x80) & 0b00001111;
// si index == 0 on locke, si index == 3 on délocke ???
if(byindex == 0) {
// ??? byLockOdo = LOCK_ON;
}
// on envoie la valeur de l'adresse (index) préalablement reçue
i2c_write(abyBufferI2c[byindex]);
// ??? déblocage manuel du clock
CKP=0;
if(byindex == 3) {
byLockOdo = LOCK_OFF;
}
}
} |
I am not able to make the system work, could you help, please? |
|
|
jenipapo
Joined: 27 Jan 2008 Posts: 4 Location: France
|
|
Posted: Mon Aug 09, 2010 8:36 am |
|
|
Sorry!
At the end of the code, its CKP=1 instead of CKP=0. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Aug 09, 2010 9:44 am |
|
|
So did you fix the problem or did you just forget a piece of code?
If you didn't solve, then before everyone jumps in, you should post a small and complete version of test code to show your problem.
Your initial post is not complete and I'm guessing if you do post the whole thing, it will include a lot more than most are willing to debug for you.
Typically CKP isn't used with I2C (that's an SPI flag) so I'm not sure why you're altering it.
I2C also *requires* External pullup resistors as it's considered an open-collector/drain bus.
If you don't have these, that's why your I2C bus is resting at/near Vss/Ground.
If you are using 5V 4.7K is a nice starting value (it depends on the length of the buss.. Longer lines might need stronger pullups).
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Aug 09, 2010 11:03 am |
|
|
You don't show the I2C configuration, but I assume that you have SEN set to 1, so CKP is automatically reset after data receiption. Not setting it to 1 or missing the I2C interrupt completely would result in SCL stuck low. |
|
|
|