I'm using a USB Barcode scanner connected via a USB shield, I'm able to get the readings from the barcode using this example, After getting this readings, I'd like to save it to an SD card but the SD card won't initialize since the barcode also uses SPI, how can I deactivate the ICSP in order to activate the SD card? Or how to switch between multiple SPI slaves?

  • Possible duplicate of How to access multiple SPI interfaces on Arduino
    – user31481
    Aug 28, 2017 at 12:27
  • @LookAlterno If someone can answers how to tristate a buffer or use a multiplexer to circumvent the SD problem, it might be a useful addition and not fully a duplicate. Aug 28, 2017 at 13:37

2 Answers 2


with SPI there is an implicit slave select pin on each device that must be pulled low to enable the device.

Connect each slave select pin of the SPI device to their own unused digital pin on your arduino and keep it pulled high until you want to talk to the slave.

However not all SPI devices will properly put the MISO pin into high impedance when SS is pulled high so you may need to use a tristate buffer on that pin or use a multiplexer.

When adding your own tristate buffer (for example a HS125) you need to connect each MISO pin of the SPI device to the input of a buffer, the slave select is then connected to the output enable pin of the tristate. The outputs of the buffers can be connected together along with the MISO pins of the devices that do properly go high impedance to the MISO of the master.

When using multiplexers there are 2 options:

  1. You can daisy chain 2:1 multiplexers by connecting the MISO of the device to the 0-input of the mux and the Slave select to the select input pin of the mux.

  2. you can use a >2 multiplexer to select the correct MISO line based on the address of a set of S lines. Then with a decoder you can provide the actual SS signal to the SPI device. This way you only need 2 SS pins for 4 SPI devices.

  • 3
    SD cards are notoriously bad at playing nicely with other devices on the same bus. Especially with some adaptors with poor logic level shifting circuits.
    – Majenko
    Aug 28, 2017 at 12:25
  • I can confirm this ... I had so many problems using a (cheap) SD break card and (SPI) SRAM together, that I eventually bought a separate SD logging card. But I wonder how to implement that 'buffer' or what multiplexer (and how to use it) ... Can you explain this a bit plase? Aug 28, 2017 at 13:13

Refer to the schematic below for a visual explanation of what is explained in this thread regarding a tri-state buffer. I have used this circuit successfully on a PCB.enter image description here I got this schematic from: © 2017 Vishnu M Aiea. www.vishnumaiea.in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.