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_slaveaddr does not update the slave address on 16F18426

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



Joined: 18 Sep 2022
Posts: 12

View user's profile Send private message

i2c_slaveaddr does not update the slave address on 16F18426
PostPosted: Sun Sep 18, 2022 3:58 pm     Reply with quote

I have this #use
Code:
#use i2c(SLAVE,I2C1,FORCE_HW,ADDRESS=0x80,RESTART_WDT,NOINIT)


and this to initialize I2C (considering NOINIT)
Code:
void I2C_Initialize(unsigned int8 address)
{
   i2c_slaveaddr(address);
   i2c_init(1);
}


but no matter what address I define, it always uses 0x80. I tried without ADDRESS=0x80 but then the I2C port doesn't work on any address.

I also tried
Code:
#byte I2C1ADD=getenv("SFR:SSP1ADD")
#byte I2C1CON=getenv("SFR:SSP1CON1")
#bit I2C1EN=I2C1CON.5

with
Code:
void I2C_Initialize(unsigned int8 address)
{
   I2C1EN=FALSE; //stop the port Technically not needed with NOINIT
   I2C1ADD=address;
   I2C1EN=TRUE;
}

with the same results.
Anyone got any nuggets of wisdom?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 18, 2022 4:28 pm     Reply with quote

The i2c_init() routine is setting it to use the slave address specified in the
#use_i2c() statement (0x80).

To fix this, just reverse the order of the calls in your routine, as shown below:
Code:

void I2C_Initialize(unsigned int8 address)
{
i2c_init(1);
i2c_slaveaddr(address);  // Do this last
}
reesesm2000



Joined: 18 Sep 2022
Posts: 12

View user's profile Send private message

PostPosted: Sun Sep 18, 2022 5:07 pm     Reply with quote

I could have sworn I tried it this way too but obviously not. It is working!

Thanks for the super quick reply and on a Sunday Very Happy
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