Change I2c address

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change I2c address

2,756 Views
RicardoCazettaM
Contributor I

Hi! I'm using CodeWarrioir with PE to program a HCS08 microcontroller.

It's a fan controller and it will comunicate with the rest of System over a I2C bus as a Slave device.

For the address, I need to read some GPIO to see what is its position on a back plane. Therefore, I need to set the I2C address on-the-fly.

Looking at the ProcessorExpert windows, I didn't see an obvious way to do that. The only option I see is the "Slave address" property, wich appears to be static after the build.

My question is if there's an easy way to set the I2C Slave address of a I2C component by software, after the code starts running.

If there's not a easy way, what is the hard way I should go to get this working?

The about screen shows:

CodeWarrior Development Studio

Version: 1.0.0

Build Id: b15_2105-A22

Thank you!

0 Kudos
2 Replies

1,345 Views
marek_neuzil
NXP Employee
NXP Employee


Hello,

I am not sure which HCS08 derivative and which I2C component you use for your application but the slave address of the I2C device in the slave mode must be set before the I2C device is enabled, see the proper initialization sequence in a HCS08 reference manual:

Module Initialization (Slave)

1. Write: Control Register 2

• to enable or disable general call

• to select 10-bit or 7-bit addressing mode

2. Write: Address Register 1 to set the slave address

3. Write: Control Register 1 to enable the I2C module and interrupts

4. Initialize RAM variables (IICEN = 1 and IICIE = 1) for transmit data

5. Initialize RAM variables used to achieve the routine shown in the following figure

Whenever you need to change the slave address you should reinitialize the device. If you change the slave address when I2C device is enabled the behaviour is undefined.

So you need to rewrite the source code generated by the PEx component (you must select Code Generation - Don't Write Generated Component Modules in the pop-up menu of the I2C component and then you can modify the generated code). You can write own function for re-initialization of the I2C.

Best Regards,

Marek Neuzil

0 Kudos

1,345 Views
nikivendola
Contributor III

Hi Marek,

in the figure below you can see the time diagram of a MAG3110 I2C (slave).

Immagin2e.png
The Master is a MK10.
The addresses  of Device and Register must be written first one then after tx, the other in I2C0_A1 register?

0 Kudos