Author Topic: Hot swap SPI devices. PLZ check the schematics.  (Read 9448 times)

0 Members and 1 Guest are viewing this topic.

Offline JacquesBBBTopic starter

  • Frequent Contributor
  • **
  • Posts: 842
  • Country: fr
Hot swap SPI devices. PLZ check the schematics.
« on: September 07, 2015, 03:24:09 pm »
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 swap
SD 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 from
one to the other in order to have  the possibility to remove one in order to analyse the data, keeping a continuous record.

Thanks

Edit : PLZ check the schematics below.( answer #8 in this thread)
« Last Edit: September 11, 2015, 03:38:27 pm by JacquesBBB »
 

Offline Chris C

  • Frequent Contributor
  • **
  • Posts: 259
  • Country: us
Re: Hot swap SPI devices
« Reply #1 on: September 07, 2015, 11:52:09 pm »
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.
« Last Edit: September 07, 2015, 11:57:48 pm by Chris C »
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2830
  • Country: us
Re: Hot swap SPI devices
« Reply #2 on: September 08, 2015, 12:27:16 am »
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.
 

Offline JacquesBBBTopic starter

  • Frequent Contributor
  • **
  • Posts: 842
  • Country: fr
Re: Hot swap SPI devices
« Reply #3 on: September 08, 2015, 07:42:48 am »
SD cards are made to be hot swapped.  The VDD/GND pins stick out just a little further, so they always make contact first:

Thanks, I did not realize that. I will have to take it into account in some adaptors I made out of  micro sd card converters.

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.

This 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.
 

Offline Chris C

  • Frequent Contributor
  • **
  • Posts: 259
  • Country: us
Re: Hot swap SPI devices
« Reply #4 on: September 08, 2015, 08:56:21 am »
This 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.

Hmm.  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.
 

Offline naxxfish

  • Contributor
  • Posts: 22
  • Country: 00
Re: Hot swap SPI devices
« Reply #5 on: September 08, 2015, 04:05:51 pm »
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. 
 

Offline JacquesBBBTopic starter

  • Frequent Contributor
  • **
  • Posts: 842
  • Country: fr
Re: Hot swap SPI devices
« Reply #6 on: September 08, 2015, 04:50:09 pm »
So the question isn't so much about "SPI devices" as SD cards. 

The question is double. My immediate concern is SD card, and I am glad to learn that they behave in a better way  than with
generic 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.
 

Offline JacquesBBBTopic starter

  • Frequent Contributor
  • **
  • Posts: 842
  • Country: fr
Re: Hot swap SPI devices. PLZ check the schematics.
« Reply #7 on: September 09, 2015, 10:30:52 am »
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 will
draw 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
« Last Edit: September 10, 2015, 06:19:20 pm by JacquesBBB »
 

Offline JacquesBBBTopic starter

  • Frequent Contributor
  • **
  • Posts: 842
  • Country: fr
Re: Hot swap SPI devices. PLZ check the schematics.
« Reply #8 on: September 12, 2015, 10:29:23 am »
Does anybody can have a look to this schematics ?
I would really appreciate.

Thanks
 

Offline HowardNamath

  • Newbie
  • Posts: 5
  • Country: us
Re: Hot swap SPI devices. PLZ check the schematics.
« Reply #9 on: September 13, 2015, 10:35:46 pm »
I think you have inputs 3A and 2A swapped on that buffer symbol (SN74LVC125), probably want to double-check that.
 

Offline JacquesBBBTopic starter

  • Frequent Contributor
  • **
  • Posts: 842
  • Country: fr
Re: Hot swap SPI devices. PLZ check the schematics.
« Reply #10 on: September 18, 2015, 01:56:38 pm »
I think you have inputs 3A and 2A swapped on that buffer symbol (SN74LVC125), probably want to double-check that.

Thanks,

You are right !  I will have to correct that !
 

Offline Frant

  • Regular Contributor
  • *
  • Posts: 54
Re: Hot swap SPI devices
« Reply #11 on: September 19, 2015, 12:59:00 am »
This 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.

You may also want to consider the 74CBTLV3245 or the 74CB3T3245.
 

Offline Frant

  • Regular Contributor
  • *
  • Posts: 54
Re: Hot swap SPI devices
« Reply #12 on: September 19, 2015, 01:26:17 am »
This 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.

You may also want to consider the 74CBTLV3244.
 

Offline Frant

  • Regular Contributor
  • *
  • Posts: 54
Re: Hot swap SPI devices
« Reply #13 on: September 19, 2015, 09:30:27 am »
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.

You may also want to consider the 74CBTLV3244.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf