View previous topic :: View next topic |
Author |
Message |
reesesm2000
Joined: 18 Sep 2022 Posts: 12
|
i2c_slaveaddr does not update the slave address on 16F18426 |
Posted: Sun Sep 18, 2022 3:58 pm |
|
|
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
|
|
Posted: Sun Sep 18, 2022 4:28 pm |
|
|
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
|
|
Posted: Sun Sep 18, 2022 5:07 pm |
|
|
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 |
|
|
|