5 ms·
I think I2C and SPI have very different use cases. Over I2C, you can interact with 127 devices with just 2 pins. To do the same with SPI, you'd need 130 (4 + an
by fra 7y ago
I think I2C and SPI have very different use cases. Over I2C, you can interact with 127 devices with just 2 pins. To do the same with SPI, you'd need 130 (4 + an additional CS for every device on the bus).
You may think of the extra pins as not a problem, but on every product I've worked on we've been pin-limited on the MCU.
- TickleSteve 7y agoDon't forget the reset lines to each device that you need to release the bus when they get locked up!
- fra 7y agoNo reason why you need to reset them individually ;-).
- Ives 7y agoAgreed, but most I2C busses only have 2 or 3 devices on them. There are some boards with 16 or so devices on the same bus, but much more than that and you'd better hope you can either program their addresses or order them with a specific address, or you might end up with 2 chips with the same address.
- fra 7y agoI've worked on server hardware with dozens of devices on a bus :-). Making sure addresses were programmable was a must indeed.
- oliverx0 7y agoThis happened to me once. Used proximity infrared sensors that used I2C with a fixed address. Needed to use multiple of them. I was able to fix it with a tri-state buffer, but quite the pain to figure out why things were not working and coming up with a solution.
- vvanders 7y agoNot always the case that you need the pin count, a good number of SPI devices support daisy chaining[1]. [1] https://www.maximintegrated.com/en/design/technical-documents/app-notes/3/3947.html https://www.maximintegrated.com/en/design/technical-document...
- andyjpb 7y agoIf you only want to select one device at a time (which is often the case) then you only need log2(devices) pins on the microcontroller because you can decode that binary number into the appropriate chip select. Obviously that requires more hardware on the board tho'.
- clarry 7y ago> Over I2C, you can interact with 127 devices with just 2 pins. In practice, I don't see that many chips offering 7 bits of address configuration. You buy a chip, it has a hardwired address. Maybe a pin or two for selecting another address.
- photojosh 7y agoThere was the design I did quite a few years ago now. Grabbed a old design, changed the board shape, put a third I2C device on. Everything powered up beautifully first go... and it was only then we worked out two of the devices from different vendors had the same I2C address. <facepalm>
- danellis 7y agoThat's still seven bits of address, though. If you're lucky, the hardwired part will be different enough between chips that you can still have a significant number of them on a bus.
- rcxdude 7y agoI've yet to get above 4 devices without conflicts. Even with evenly distributed addresses, you reach about 50% chance of conflict with 13 devices because of the birthday paradox.
- nlfwhulsdhouv 7y agoI don't think I've ever run more than 5 or 6 devices on an I2C bus without running into rise time, bus contention, or address collision issues. Some devices scoop tons of addresses, and most only allow re-assignment to a few alternate addresses. I agree it's still lower pin count than SPI, but realistically you don't get anywhere near 127 devices.
- tropo 7y agoFor that many devices on SPI, run 7 pins to an address decoder that fans out to 128. You can do this in the spare pins of an FPGA that you might have for some other purpose, and the 7 pins are cut down to one or less if you've already put much into the FPGA. For example, the FPGA provides 4096 bytes of registers (12 address bits) to the MCU but only needs 3700 registers, so use one of the spare bytes to control which SPI CS is enabled. I've also seen JTAG as an alternative to I2C and SPI. JTAG can be part of normal operation.
- crtlaltdel 7y agothis is a very good point, and i have had the same experience. its also super common for very cheap, very low end custom ics to use i2c for the same reason; keeping the pin count and package size down