Brain fried trying to work out Hex address of PCA9685

Hi

Got a PCA9685 PWM driver on i2c bus.

Default address is 0x40.

I want to install a rotary Hex switch to allow me to select 10 addresses on the bus.

But... that address cannot start at 0x40, as that clashes with other IC's that do not have adjustable addresses.

The PCA9685 has 6 address pins, but for the life of me I cannot work out what pins I am supposed to be altering to get the address to start elsewhere.

Ideally, the range would start at 0x50 and go up 10, but at this point..... my brain is fried.

I clearly need to 'hardwire' part of the address to shift it away from 0x40, and maybe starting at 0x50 isn't possible. Any advice?

The way I read the datasheet, if you set A5 permanently low, and A4 permanently high, then the base address will be 0x50, you can then set A3-A0 by DIP or rotary switch to create 16 devices (with addresses 0x50 to 0x5F).

1 Like

I think I have it....

1 Like

That looks good :slight_smile:

In this configuration you would use the "Standard Output" version of the switch.

I think you got it.

Something to understand to avoid confusion is that the "Fig 4 SlaveAddress" (and probably other parts of the data sheet) is showing an 8-bit i2c address, where bit 0 is the read/write control bit. But in Arduino world, we ignore that bit (it is taken care of behind the scenes by the Wire library) and use 7-bit addresses.

Yea... My brain just said... enough earlier

Quick question regarding multiple detection of the same address...

I have put (rightly or wrongly) an ATtiny85 on my slave boards that does nothing but broadcast a reference address so that the main CPU can identify what modules are attached at boot.

Now I understand I could achieve the same thing simply reading all the addresses on the second i2c bus and working out what was attached.

But, my thinking (which I now think is flawed), was that I only wanted the main module talking to modules it had identified at boot. Anything added to the i2x bus after the boot point would be ignored, as the main code would not have initialised it.

My problem.

The slave modules have a single address on an i2c 'ID bus'. This but does nothing but identify modules at boot.
So say 5x MCP23017 multiplexers all have the id address of say 0x20. Yes.... not great.

But those identified modules then have a separate i2c bus for data comms which is selectable with the rotary switch above.

This means that you might have 5x modules with different comms addresses, but the id address is always going to be the same (because there is only one id address for each type of module).

What happens when the i2c bus detects the 5x same id addresses? Will it freeze?
I really don't want to have to implement 2x sets of rotary address switches for both the id and the comms.

Maybe.... I just bin the id system, but I kinda liked it.

Good question, I am not sure. I suspect you get corrupted data as two slaves try to reply. I2C lacks a CRC, so it is difficult to tell when errors occur.

With I2C either use an I2C multiplexer or a custom multiplexing scheme, e.g. selectively disable the SDA on certain slaves.

Identifying addresses in a broadcast bus is of course an age old problem. Generally the solution is to avoid the need and use preconfigured addresses, or use a "side door" with a different topology. A daisy-chain or selective address topology makes it possible. So either daisy chain the ID bus, or use an address select pin (like SPI).

For a multi-drop RS232 network I did, I daisy-chain a "CONFIG" line, which allows the master to discover and configure devices in the chain.

I suspect my best option is just to bin the 'id' bus and stick with just searching the main comms bus for addresses at the start.

Don't know why I went down this route

I have altered the system.

Only modules that don't use i2c (for example, the SPI modules) have an ATtiny85 to broadcast a 'I'm here' address.

The other modules that are on i2c by default are identified by their i2c address

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.