Hot swap SPI devices. PLZ check the schematics. - Page 1
Forum section: electronics / projects

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: September 07, 2015, 03:24:09 pm
content: Dear All,I would like to know if it is always safe to hot swap/remove some SPI device,assuming that it is not the one selected by CS.The question is general, but the immediate application I have is to swapSD cards connected with SPI on an Arduino.I assume that I have properly closed the files on the SD card (SD.close() using the SdFat library) .Edit : More precisely, I want to have two SD cards on the same SPI bus, and being able to toggle fromone to the other in order to have the possibility to remove one in order to analyse the data, keeping a continuous record.ThanksEdit : PLZ check the schematics below.( answer #8 in this thread)

author: Chris C
author_rank: Frequent Contributor
timestamp: September 07, 2015, 11:52:09 pm
content: SD cards are made to be hot swapped. The VDD/GND pins stick out just a little further, so they always make contact first:Although I'm not sure about using two attached to the same bus. I see one possibility for issue. Upon insertion, the SD pin connected to SPI MISO might become connected before CS does, or some other transient condition could exist where both SD cards are simultaneously trying to control MISO, causing a glitch in any attempt to read data.This could be addressed in software by:1) Reading multiple times, and accepting the data only when it reads 2-3 times identically. You're primarily doing writes, so that wouldn't be too big of a burden.2) Reading with a checksum.3) Ensuring no reads occur during the swap.Or in hardware by using two separate MISO lines. On a PIC that allows remapping MISO to various pins via its PPS function, this would be easy. Not sure how AVR/ARM/others handle it. If the platform doesn't allow it, it's possible you could bitbang SPI transfers in software to allow arbitrary pins - maybe even just for reads, with writes being done with the SPI peripheral.

author: ajb
author_rank: Super Contributor
timestamp: September 08, 2015, 12:27:16 am
content: You could also use an external buffer to prevent any glitches from making it to your MCU via MISO. A 74LVC1G125 in series with each MISO line with OE tied to the corresponding CS line ought to do the trick while being completely transparent to both the MCU and SD card.

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: September 08, 2015, 07:42:48 am
content: Quote from: Chris C on September 07, 2015, 11:52:09 pmThanks, I did not realize that. I will have to take it into account in some adaptors I made out of micro sd card converters.Quote from: ajb on September 08, 2015, 12:27:16 amThis will probably the solution I will select, as I want the double SD module to operate safely, independently of the software.Will it be better to add the buffers also to the MOSI lines ? In this case I could add a 74LVC125 quad buffer on the module.

author: Chris C
author_rank: Frequent Contributor
timestamp: September 08, 2015, 08:56:21 am
content: Quote from: JacquesBBB on September 08, 2015, 07:42:48 amHmm. I imagine a scenario where the connectors are dirty or failing, and during the part of the insertion/removal phase where all pins should be connected, the VDD connection gets broken for a few ms. The card might then see a high MOSI as an overvoltage, and attempt to clamp it to an internally falling VDD. If that action temporarily exceeds the MCU's maximum source current on that pin, it will drop the shared MOSI to logic low.Not sure how realistic this is, but it sounds like you need to guard against all possibilities. Putting a resistor on each leg of MOSI, sufficient in value that neither leg can pull the other's MOSI down, would be sufficient. Or if you can get separation for free with an IC you're already adding, all the better.

author: naxxfish
author_rank: Contributor
timestamp: September 08, 2015, 04:05:51 pm
content: So the question isn't so much about "SPI devices" as SD cards.SD cards are pretty much fine (as above) since they're designed to do that - and the pins all have ESD clamping diodes on them and all that other good stuff that stops them from getting blown up whilst they're disconnected/being connected. Most MCUs will have those on IO pins too (check the datasheet). As long as you're careful about your initialisation code (such that you assume that the card might get removed at any point), should be fine.BUT - that may not be the case of all "SPI" devices - so if you had a "hot swap" interconnect between boards, SPI or otherwise, there are additional design considerations to be made.

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: September 08, 2015, 04:50:09 pm
content: Quote from: naxxfish on September 08, 2015, 04:05:51 pmThe question is double. My immediate concern is SD card, and I am glad to learn that they behave in a better way than withgeneric SPI devices, but I am also interested in other SPI devices hot swap.For example, I am considering the calibration of various sensors that are put on small daughter boards.I want then to be able to change them without rebooting each time, just to calibrate.

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: September 09, 2015, 10:30:52 am
content: Thanks for this detailed account.Here is the schematics of the project I have for a small 2 sd card board.The leds are for controlling the traffic and which sd card is activated.The switch is for turning off these leds for saving power if needed. The traffic leds do not need that as they willdraw very little current in average.The push button is for toggling between the SD cards (with the MCU).Edit : added the decoupling caps which I had forgotten.Is this OK ?Thanks

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: September 12, 2015, 10:29:23 am
content: Does anybody can have a look to this schematics ?I would really appreciate.Thanks

author: HowardNamath
author_rank: Newbie
timestamp: September 13, 2015, 10:35:46 pm
content: I think you have inputs 3A and 2A swapped on that buffer symbol (SN74LVC125), probably want to double-check that.

author: JacquesBBB
author_rank: Frequent Contributor
timestamp: September 18, 2015, 01:56:38 pm
content: Quote from: HowardNamath on September 13, 2015, 10:35:46 pmThanks,You are right ! I will have to correct that !

author: Frant
author_rank: Regular Contributor
timestamp: September 19, 2015, 12:59:00 am
content: Quote from: JacquesBBB on September 08, 2015, 07:42:48 amYou may also want to consider the 74CBTLV3245 or the 74CB3T3245.

author: Frant
author_rank: Regular Contributor
timestamp: September 19, 2015, 01:26:17 am
content: Quote from: JacquesBBB on September 08, 2015, 07:42:48 amYou may also want to consider the 74CBTLV3244.

author: Frant
author_rank: Regular Contributor
timestamp: September 19, 2015, 09:30:27 am
content: Quote from: JacquesBBB on September 08, 2015, 07:42:48 amYou may also want to consider the 74CBTLV3244.