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

I2C slave again and again and again and ...
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 10:04 am     Reply with quote

Oups, it works.
Code:
incoming = SSPBUF;

I2C writing process works now.
The interrupt occurs 5 times! Correct Smile
(Slave addressW, 0x00, 0xAA, 0x55, 0xA5) forget about 0x5A, i removed it.
[No interrupts for S & P]

Still have a problem in the reading process. The interrupt occurs only three times (Slave addressW, 0x00 & Slave addressR) instead of 6. the last three are related to collecting data from slave Mad
[SCL stays LOW]

my isr is:
Code:

void SSP_isr(void)
{
   BYTE incoming, state;
   
   state = SSPSTAT & SSPSTATMASK;
   
   RX_LOS_SFP = 0;   //LED indicator
     
   switch (state)
   {
   case 0B00001001:  // i2c write operation, last byte was address
      incoming = SSPBUF;
      InternalAddress = TRUE;
      if (incoming == 0xE0)   // check address
      {
         PORTA ^= 0x01;
      }
   break;
   
   case 0B00101001:  // i2c write operation, last byte was data
      //incoming = i2c_read();  // data read
      incoming = SSPBUF;
      if (InternalAddress)
      {
         InternalAddressCounter = incoming;
         InternalAddress = FALSE;
         if (incoming == 0x00)    //check internal address
         {
            PORTA ^= 0x01;
         }
      }
      else
      {
         Page[InternalAddressCounter++] = incoming;
      }
   break;
   
   case 0B00001101:  // i2c read operation, last byte was address     
      incoming = SSPBUF;   //dummy read
      i2c_write(Page[InternalAddressCounter++]);  // data write
   break;
   
   case 0B00101100:  // i2c read operation, last byte was data
      i2c_write(Page[InternalAddressCounter++]);  // data write
   break;
   
   case 0B00101000:  // slave i2c logic reset by NACK from master
     
   break;
   
   default:
      if (BF)
      {
         incoming = SSPBUF;
      }
   break;
   }

   SSPOV = 0;
   RX_LOS_SFP = 1;   //LED indicator
}


!?
Matro
Guest







PostPosted: Tue Apr 08, 2008 11:20 am     Reply with quote

Then try with this isr:
Code:

#INT_SSP
void i2c_isr()
{
   unsigned int8 state;
   state = i2c_isr_state();
  if(state >= 0x80)
  {
     i2c_write(state);
     //you can add here a serial trace or a LED toggle (not on port C)
  }
  else
  {
    state = SSPBUF
    //you can add here a serial trace or a LED toggle (not on port C)
   }
}


or you can also try to change your isr to :
Code:

#int_SSP NOCLEAR
void SSP_isr(void)
{
   BYTE incoming, state;
   
   state = SSPSTAT & SSPSTATMASK;
   clear_interrupt(int_SSP);
// continue te code


Matro
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 11:41 am     Reply with quote

Are we talking about compiler bugs ?!?!?!?!? Shocked
Note that PIC18F2431 has an SSP and not an MSSP.

I'll try it by tomorrow, I'm out of the lab right now.

Thanks again Smile
Matro
Guest







PostPosted: Tue Apr 08, 2008 11:45 am     Reply with quote

Maybe a compiler bug or a mistake in the device header file.
We should analyze the .lst file generated by compilation but I've got no time for that.
You can send a mail to CCS support if you strongly believe in a compiler bug.

Matro.
Matro
Guest







PostPosted: Tue Apr 08, 2008 11:49 am     Reply with quote

And yes, 18F2431 SSP doesn't support master operation at hardware level but only through software emulation.
Matro.
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 6:09 am     Reply with quote

It works now Smile
my ISR:
Code:

#INT_SSP
void SSP_isr(void)
{
   BYTE incoming, state;
   
   state = SSPSTAT & SSPSTATMASK;
 
   switch (state)
   {
   case 0B00001001:  // i2c write operation, last byte was address
      incoming = SSPBUF;   //dummy read
      InternalAddress = TRUE;
   break;
   
   case 0B00101001:  // i2c write operation, last byte was data
   case 0B00100001:  // strange state !?!?!?!?!?
      incoming = SSPBUF;   //data read
      if (InternalAddress)
      {
         InternalAddressCounter = incoming;
         InternalAddress = FALSE;
      }
      else
      {
         Page[InternalAddressCounter++] = incoming;
      }
   break;
   
   case 0B00001100:  // i2c read operation, last byte was address     
      SSPBUF = Page[InternalAddressCounter++];  // data write
      CKP = 1; // release the clock
   break;
   
   case 0B00101100:  // i2c read operation, last byte was data
      SSPBUF = Page[InternalAddressCounter++];  // data write
      CKP = 1; //release the clock
   break;
   
   case 0B00101000:  // slave i2c logic reset by NACK from master
      InternalAddress = TRUE;
   break;
   
   default:
     
   break;
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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