I2C User Defined Serial Number Chip - Set Binary Number, Retrieve Number From I2C? Possible?

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
Hello,
I am wanting to be able to define a number via hardware or switches, and have the ability to read this number through I2C.
For example, say I want to define a single number within the range of 0 through 63, this would normally take 6 binary bits to define.
Does there exist a chip that I could define what those 6 bits/pins are (high/low), in turn define a number between 0 to 63, and then using I2C I could then retrieve this number?
I have been searching around on google, but don't really know what this might be called.
Or is there a better solution to this?

My goal is to be able to detect what circuit is connected through this method, then execute the corresponding code that goes along with that circuit. Each circuit type would have its own unique number. I don't want to use 6 pins to do this though.

Thanks and any help is greatly appreciated!
 

AlbertHall

Joined Jun 4, 2014
12,347
Or if you want to have the switches connected to the I2C chip then I think the option is a microcontroller of some sort which could read the switches and be an I2C slave device.
 

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
The more I think about this... I'm starting to wonder if the way to go is to just use an I2C I/O expander? Have the I2C I/O expander GPIO's tied high and low to make the binary number, then use I2C communication to retrieve the state of the GPIOs, and convert that to the binary number. They are a tad more costly than I would hope for, so curious if there is still a better way of doing this.
 

dendad

Joined Feb 20, 2016
4,479
An I2C expander will work well. Add a HEX rotary switch or DIP switch to set the number. I use these 16 bit ones. some pins can be the switch inputs and the others are free for inputs or outputs.
http://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf
If you don't need to set the number, just read an exclusive one, look at the 1 wire series of devices. They have a number of functions and all include a unique serial number. Like the DS18S20 temperature sensor.
See this for some info..
https://playground.arduino.cc/Learning/OneWire
 

Raymond Genovese

Joined Mar 5, 2016
1,653
The more I think about this... I'm starting to wonder if the way to go is to just use an I2C I/O expander? Have the I2C I/O expander GPIO's tied high and low to make the binary number, then use I2C communication to retrieve the state of the GPIOs, and convert that to the binary number. They are a tad more costly than I would hope for, so curious if there is still a better way of doing this.
If you are set on only reading the state of six pins than maybe the expander is fine. If you want more flexibility and a cheaper price, consider programming a PIC as an I2C slave device at ~$1US. You can even send commands and receive responses.

I am currently working on a project for an I2C GP PWM using this approach. Previously I did a project using a PIC as an I2C slave to read multiple sensors.

The approach may be worth considering, again, depending upon the flexibility that you want/need.
 
Top