Main Site Documentation

Multiple Devices on a Single SPI Bus


I have a project in which I’m using multiple SPI ADCs on a single SPI bus (Microchip’s MCP3208). It works just fine with a single device on the bus, or with two devices on different buses. However, I get an error when I try to create a second SPI object on a bus.

Here’s an example:

SPI SPI_A = new SPI(new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di26, false, 0, 0, false, true, 2000, SPI.SPI_module.SPI2));
SPI SPI_B = new SPI(new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di24, false, 0, 0, false, true, 2000, SPI.SPI_module.SPI2));

When I try this, I get a System.InvalidOperationException on the second line. If I change the bus to SPI1 on ether the first or second line it works just fine.

Has anyone been able to run multiple SPI devices on the same bus? Any suggestions?



You can only create one SPI bus at a time but you can have many device configurations, All you do is create a config for each device. The examples on wiki and code will assist you here…

Welcome to the forum by the way.

Cheers Ian


Ah, I see. The SPI object is more like a bus than a device.

Thanks! (and thanks for the welcome)


Yes you got it…think of it as SPIbus

Same applies to I2C


Thanks. I also have multiple I2C devices on the same I2C bus, so I’m sure I would have run into the same problem. Psychic support is always helpful!


The community said I am an automated support bot but psychic is a new one. I guess my “AI bot” skills have been improved to know the future! :slight_smile: love it!


Gus! I thought your support bot was called Architect!! :smiley:

Cheers Ian


Ha-ha! :o