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

dual i2c on 8722

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 22, 2007 2:09 am     Reply with quote

You could write a substitute routine for the bad library code. Only the
i2c_write() function has a problem and only in the 2nd SSP module.
One easy way to do this is to look at the ASM code in the .LST file
and write C code that does the same thing. I've done this below.

Here's the corrected ASM code for the i2c_write() function for the 2nd
i2c port on the 18F8722. I've fixed the register address and bit position
for the SSP2IF bit, and I've added comments:
Code:
/
/*
... #use i2c(master, sda=PIN_D5, SCL=PIN_D6, FORCE_HW)
00004:  BCF    F63.7   // Set WCOL2 = 0
00006:  BCF    FA4.7   // Set SSP2IF = 0
   
00008:  MOVFF  07,F66  // Put byte into SSP2BUF

0000C:  MOVLW  02
0000E:  BTFSC  F63.7   // Test WCOL2 
00010:  BRA    001C    // Return 2 if WCOL2 = 1.

00012:  BTFSS  FA4.7   // Test SSP2IF
00014:  BRA    0012    // Wait in loop if SSP2IF = 0

00016:  MOVLW  00
00018:  BTFSC  F62.6   // Test ACKSTAT
0001A:  MOVLW  01      // Return state of ACKSTAT
0001C:  MOVWF  01
*/


Here's a functional translation of the above ASM code to C. It doesn't
compile to exactly the same ASM code, but it performs the same functions.
Code:

// Define registers and bits used by the routine.
#byte SSP2CON1 = 0xF63
#bit  WCOL2 = SSP2CON1.7

#byte PIR3 = 0xFA4
#bit  SSP2IF = PIR3.7

#byte SSP2CON2 = 0xF62
#bit  ACKSTAT2 = SSP2CON2.6

#byte SSP2BUF = 0xF66

// Here is the new routine.  Call it instead of i2c_write()
// in the CCS library code for the 2nd SSP module.

int8 i2c_write_ssp2(int8 value)
{
int8 retval;

WCOL2 = 0;
SSP2IF = 0;

SSP2BUF = value;

if(WCOL2)
  {
   retval = 2;
  }
else
  {
   while(!SSP2IF);
   retval = ACKSTAT2;
 }

return(retval);
}
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