Thursday, August 8, 2013

3-State Jumper

Up to 27 A2D adapters can live on the same I2C bus. The address is configured with 3 jumpers, each with 3 states: soldered high, soldered low, and unsoldered. Pull-down and pull-up resistors are the key to detecting all three states.


I use a 220k pull-down resistor on each of the pins. That's because the MCU I'm using has a 50k pull-up resistor. If the jumper is left disconnected, it is pulled down with the 220k resistor and appears logic low until  the 50k pull-up resistor is enabled creating a voltage divider that applies logic high to the pin.

Internal 50k pull-up used to detect if jumper connected to VCC, GND, or nothing.

If the pin is high regardless of the pull-up resistor, it's because it's been soldered to VCC. Likewise if the pin is low regardless of the pull-up, it's soldered to GND.


Here's the code to get the address based on the jumper attached to the specified pin. ADDR_PORT and ADDR_DDR are defined in this case as PORTA and DDRA

One tip: put a delay between setting the pull-up and reading the pin state or it won't work. I think this is due to the clock synchronization talked about in the datasheet for the ATtiny44A. I tried using a NOP but it may have been optimized away; it didn't work.

Converting To Decimal

If you have 3 jumpers as the I2C adapter does, one must convert from trinary (base-3) to Decimal (base-10). Or, whatever base you want to work with. Let's say you get the trinary values a0, a1, and a2 from each of the jumpers. The conversion isn't all that different from binary to decimal.

You can generalize this to n jumpers, as you might imagine:

I'm sure there are better resources on base conversion out there, so I'll quit while I'm ahead.

1 comment:

  1. Wow, that is clever! Thanks. Of course if you have an ADC, you could have a whole mess of different states from one pin. This is sort of a simplified version of that.