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 slave scl and sda stick to gnd

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



Joined: 27 Jan 2008
Posts: 4
Location: France

View user's profile Send private message

i2c slave scl and sda stick to gnd
PostPosted: Mon Aug 09, 2010 8:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 09, 2010 8:36 am     Reply with quote

Sorry!
At the end of the code, its CKP=1 instead of CKP=0.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Aug 09, 2010 9:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Aug 09, 2010 11:03 am     Reply with quote

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.
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