Identification of pcb-card via I2C or SPI Bus - Page 1
Forum section: electronics / beginners

author: chrisss
author_rank: Newbie
timestamp: August 07, 2016, 07:37:42 pm
content: Hi everybody,winter is coming so i plan a nice winterproject for myself and a friend.It should be an Audio Preamp with say 8-10 card slots for various extension-cards to be able to swap the configuration simply by swapping the Input or Output modul, to be able to easily do revisions or bring new ideas on the table over the years or design new moduls (new phono modul or whatever). without designing a complete new Preamp.The whole system should be controlled by a MCU.What I am thinking of is, how do I inform the MCU about what`s in every Card-slot so the menu could be altered for the actual configuration?for example: I turn on the Amp and Slot 1 says: "I am a MM Phono Card". Slot 2 says: "I am a DAC Card". etc.etc.so I can control every Card directly because they could have different Functions and the menu is set according to the cards in the slots.How can I realise something like that? Via I2C, SPI?, specific EEprom? Or does anybody know for what "Term" I have to search in google to find what I need?I searched google for a while, but haven`t found what I`m looking for.Can anybody help me out with some info?Thank youBestChrisss

author: madires
author_rank: Super Contributor
timestamp: August 07, 2016, 07:55:20 pm
content: A lot of systems use an I2C EEPROM for identification (module, revision, parameters, etc.).

author: rstofer
author_rank: Super Contributor
timestamp: August 07, 2016, 07:57:31 pm
content: You could have the card put a parallel binary word on the bus if the bus is wide enough. Send a binary word containing the slot address and expect back a binary word indicating which kind of board is installed (or some default value (all 1's?) if no card is installed).More elegant would be an I2C bus where each card had a very small MCU that could respond. I'm thinking I2C because it takes less pins. But it's slower than SPI so if you plan to move music, this isn't the way to do it.I like SPI but the requirement for a separate CS' signal for each slot soon eats up a lot of pins. Of course, you could do address decoding on the card MCU and you could then just use a binary address of the bus. Four bits could select 16 cards instead of just 4.Maybe I would go with I2C... I could have the on-card MCU take care of pot adjustments after the master sends an appropriate command.If I were planning to have an MCU on each card, I might even think about a more general purpose solution like RS-485. The ROBIN protocol is a multi-master arrangement for serial buses:http://www.bdmicro.com/code/robin/

author: chrisss
author_rank: Newbie
timestamp: August 07, 2016, 08:32:41 pm
content: wow! hat was quick. :-)thank you!actually it seems to be not a bad idea to have a small mcu on each board. Hmm...well, no audio will be transfered via the pins. only SPI, I2C for control and I2S for Audio.in the end the naked preamp is a DSP, a MCU, CD Drive and a Media Player, a Diplay and a couple of buttons/encoders.Excuse me, I am not that good on this this I2C/SPI topic, but how do I read out the EEprom of the Extension-Card it doesn`t have a I2C Adress, right?Or can I simple put a 1:8(10) multplexer/switch between the main MCU and the extension-cards.Thank Youchrisss

author: kc8apf
author_rank: Regular Contributor
timestamp: August 07, 2016, 09:00:17 pm
content: I2C eeproms have a preset address. Often you can change a few bits via pins so multiple eeproms can be used on the same bus. When you have plugin cards on a backplane, putting an I2C mux on the backplane helps not only with address collisions but also stuck slaves.Sent from my Nexus 5X using Tapatalk

author: rstofer
author_rank: Super Contributor
timestamp: August 07, 2016, 09:29:34 pm
content: I2C devices have a 7 bit address. Of those, 2 or 3 bits are usually brought out on pins so the specific device address can be set. Additionally, you will often find two devices with slightly different I2C address blocks so you can install twice as many of them. Of the first couple of datasheets I looked at, the high 4 bits are locked to 0xA and the lower 3 bits are user selectable. I know I have seen devices with options for the base address.

author: chrisss
author_rank: Newbie
timestamp: August 07, 2016, 09:34:44 pm
content: So a good idea would be to give every extension-card the i2C bus address 8 for example and the mcu switches on start up through all card slots and ask: "what kind of card are you?".right?

author: kc8apf
author_rank: Regular Contributor
timestamp: August 07, 2016, 11:07:09 pm
content: Quote from: chrisss on August 07, 2016, 09:34:44 pmYes. Use an I2C mux and you're good to go.Sent from my Nexus 5X using Tapatalk

author: johnkenyon
author_rank: Regular Contributor
timestamp: August 08, 2016, 07:24:20 am
content: Quote from: rstofer on August 07, 2016, 09:29:34 pmMost I2C EEPROMS have two address pinsBring out the address pins to the card connector.On the motherboard, hard wire the 2 address pins to 0v or Vcc so that the first slot has 000, second slot has 001 etc.When it comes to card detection, scan the bus for each device address - if the device is present, then there is a card in the slot.This means you can kill two birds with one stone - you remove the need for for a MUX (for up to 4 cards), and you have a mechanism for card detection.The cost for this is two pins used on the connectorIf you need 8 cards instead of 4, then you are looking at a 2:1 MUX instead of an 8:1 MUX.

author: Kilrah
author_rank: Unknown
timestamp: August 08, 2016, 07:41:19 am
content: Supposing the main MCU has enough pins I would use SPI and a different CS line for each slot, so the location identification is trivial. Saves the use of a mux.

author: Ian.M
author_rank: Super Contributor
timestamp: August 08, 2016, 09:54:20 am
content: The advantage of the I2C Mux, is you have a local I2C bus for each card that can be used to monitor and control it via I2C I/O expanders, digipots, DACs and ADCs etc. Although you can do something similar with SPI, the number of /CS lines required to each card rapidly becomes ridiculous.Consider using a MCU that can execute from RAM or writing a script bytecode interpreter. Then you can load custom routines from the card ID EEPROM (after checksumming), allowing per card customisation without revising the main unit firmware. Use EEPROMs with a write protect pin!

author: rudika79
author_rank: Regular Contributor
timestamp: August 08, 2016, 11:40:39 am
content: You can use 1wire eeprom device from Maxim.

author: poorchava
author_rank: Super Contributor
timestamp: August 08, 2016, 12:09:46 pm
content: ou can also use a simple MCU (think PIC10F, PIC12F, ATTiny13 or something like that) thet will measure voltage on some resistor dividers and report that over any digital multidrop bus (i2c, 1-wire etc).It's prett easy and requires only fitting different resistors (much like nVidia hacks, which changed normal GPU into Quadro)

author: chrisss
author_rank: Newbie
timestamp: August 08, 2016, 03:20:00 pm
content: Thank you, thank you, thank you for all these ideas/help!!This forum has awesome contributors.well, this one-wire with voltage measurement sounds great.

author: batteksystem
author_rank: Regular Contributor
timestamp: August 10, 2016, 01:40:10 pm
content: Quote from: chrisss on August 07, 2016, 07:37:42 pmI2C is better, delegate one CS pin for each card is simply not feasible

author: Ian.M
author_rank: Super Contributor
timestamp: August 10, 2016, 01:52:16 pm
content: +1TwoPCA9548A8 way I2C multiplexers on the main board gives you the capability to support 16 sub-busses with no address conflicts between them except for the PCA9548A mux addresses. Therefore all the card ID EEPROMs can have the same address, and any I2C interfaced analog or digital I/O on each card can be at addresses listed in the ID EEPROM with no risk of conflict with devices on a card in a different slot. Treat any I2C stuff on the main board apart from the muxes as if it was a card in a slot and you avoid conflicts with that as well + leverage the code you have already written for managing peripherals on pluggable cards.

author: rstofer
author_rank: Super Contributor
timestamp: August 11, 2016, 02:32:30 pm
content: It is true that the main board would need one CS' output per peripheral card slot for SPI. But there is no reason that the individual cards have more than one CS' - their own. The advantage to this is that the host can address a SLOT and determine what kind of board is installed.I2C has some advantages but it becomes unwieldy when you run out of address bits. In the case of EEPROMs, that is usually just 3 bits or 8 possible locations. Even if this was workable, how does the card know what slot its in? Does the card need to be able to tell the host which slot? Is there anything unique about certain slots?

author: Kilrah
author_rank: Unknown
timestamp: August 11, 2016, 02:55:58 pm
content: The i2C mux handles that, becasue the micro knows what slot it selects on the mux. Then each card can have the entire i2c address space.

author: Ian.M
author_rank: Super Contributor
timestamp: August 11, 2016, 03:35:00 pm
content: Exactly, except for the address(es) of the mux(es). That means you can put whatever I2C controlled peripherals you like on the card and it will not conflict with the rest of the system even if there is an *IDENTICAL* card in the next slot.I2C controlled stuff you might want to put on a card could include cross-point switches so the system can command the card to map its inputs and outputs to whichever uncommitted lines are available bussing the slots together, to route the audio through a chain of effects cards in whatever order is desired.Taking another look at the alternatives:SPI would need a /CS per card + SDI/SDO and SCK and wouldn't give you on-card peripheral control without additional /CS lines. Although its potentially faster, its too clumsy and uses too many connector pins - which would be in short supply due to the demand for card to card interconnects in a fully reconfigurable system.Dallas 1-wire is possible for the card ID purpose, but its slow and lacks the wide range of peripheral chips available with I2C interfaces. It would still need a multiplexor on the main board, and to avoid compounding its performance problems, that mux should *NOT* be 1-wire controlled.The Analog solution would be one or more resistors between dedicated pins on the connector. Analog switches on the main board would connect each slot in turn to a circuit that reads the resistance(s). The cards would be 'programmed' at build time by fitting the desired resistor values. However it would be difficult to 'store' more than four or five bits per resistor reliably as one needs to maintain enough separation between adjacent values to avoid mistakes due to contact resistance, noise and limited ADC resolution.

author: Kilrah
author_rank: Unknown
timestamp: August 11, 2016, 04:29:22 pm
content: Quote from: Ian.M on August 11, 2016, 03:35:00 pmI mentioned it as an option because as usual the OP didn't give enough detail.If there are 8 card slots, 8 CS lines may not be a problem.If each card has its own MCU which I'd imagine very likely, then on-board addressing is handled by it anyway.An I2C mux on the mainboard and 8 pairs of SDA/SCL lines would actually be more routing.I2C expanders on the cards may mean too little throughput.We can't know what's most appropriate in his context, so just shooting options for his consideration.

author: macboy
author_rank: Super Contributor
timestamp: August 11, 2016, 04:47:21 pm
content: I would use small I2C EEPROM having 3 address lines. E.g. a 24C02 has 256 bytes of storage and 3 address lines. Use 3 pins of your card connector as the address lines, and two more for the data and clock; on the amp "motherboard" these address lines will be connected to ground or digital Vcc as appropriate to effect the addresses of 0 to 7 for the 8 different slots. The EEPROM on the cards will be connected to these address lines, as will any other digital logic on the card that might need to know its slot number. All 8 of the EEPROMs can be simply connected in parallel (shared clock and data lines) since they have each a unique address defined by the slot number. The microcontroller can then easily and quickly scan all slots for presence and type of card.If you need to extend past 8 slots then you can use a separate I2C bus (just two lines) to give you 8 more slots.

author: rstofer
author_rank: Super Contributor
timestamp: August 11, 2016, 05:41:38 pm
content: If each card had an MCU, there is another approach that only takes four wires, regardless of the number of cards. Something a lot like Token Ring. Actually, two wires in and two wires out...During power-up, the first card in line receives an initialization message from the host telling it to initialize and return its ID. Initialization messages after this will be passed to the second card and, eventually from the second card to the third, and so on. Along the way, each card assigns itself a slot number and after this process is complete, all cards can be addressed by slot number. It does require some amount of 'store and forward' capability but that would be some kind of background, interrupt driven, process.It could also be formulated as a recursive process when the host tells the first card to initialize, the first card tells the second, and so on, passing the next available slot number in the message. Each card would look for a return response from the succeeding card and, failing to get one, could notify back down the wire that no such card exists.It would also require that the card MCU have two serial ports. Actually, the process could be done using two SPI ports just as well.I kind of like this approach. The only physical requirement is that there be no gaps in the chain. If there are gaps, install a jumper board to jump the input and output chains.

author: chrisss
author_rank: Newbie
timestamp: August 18, 2016, 10:59:36 pm
content: That`s what I thought the last couple of days. One MCU for every extension card.Maybe SPI with a CS line for every extension slot.So every Card runs with SPI from the Mainboard.The ext. card MCU controls the onboard ICs. Because some ADCs or Preamp Chips run with I2C or SPI or something else.On the other hand, I can always integrate future standards and I don`t have to use SPI with 10 CS, plus I2C for all cards, plus I2C Mux on the mainboard.I guess this option could be reasonable, right?bestchrisss

author: C
author_rank: Super Contributor
timestamp: August 19, 2016, 01:59:47 am
content: Think about the future.At some point you may put what was in many slots on one board.If you treat all the slots as a board to start with you can build a tree.Read from address A and the data says that you have X slots.Read address B of each slot of X.A slot could respond with Y slots.Read address C of each slot of Y.The Y slots could be Y functions on one board or a board with Y slots.A unique pin per slot is a good idea. The CS of SPI or the implied i2C mux