arduino:sd-card-modules
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | arduino:sd-card-modules [2024/11/22 12:02] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== SD Card Modules and their problems ====== | ||
+ | |||
+ | {{htmlmetatags> | ||
+ | metatag-description=(SD Card Modules and their problems) | ||
+ | }} | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | If your electronics project requires the use of an SD card, the solution seems to be pretty easy: purchase a very cheap SD Card Module, wire it to your controller, probably an Arduino, load the libraries and that's it. | ||
+ | |||
+ | Well, not really. In this article, we shall examine the case and understand why we need to spend some more effort to get the job done. | ||
+ | |||
+ | SD cards by themselves provide an SPI operation mode, meaning that read and write operations can be performed using the standard SPI wires (MISO, MOSI, SCK) plus a selection wire. What else is expected from an SD card module to integrate it properly and adequately into a project? I am presenting below a collection of such **criteria**: | ||
+ | |||
+ | - **A socket**, which is robust enough to withstand the designed number of in-out actions. The size of the socket should match the SD cards that we intend to use, otherwise we must select a standard SD size which will accomodate miniSD and microSD cards using appropriate adapters. | ||
+ | - **A 3.3V power source**. SD cards themselves operate at 3.3V. Some modules may contain a voltage converter and others may also contain a level shifter for the data signals. | ||
+ | - **A voltage level shifter**. As stated above, SD cards operate at 3.3V. Therefore, to interface with a 5V Arduino, the Arduino 5V signals MOSI and SCK should be converted to 3V, whereas the SD card output MISO should be converted from 3.3V to 5V | ||
+ | - **Capability to connect the SPI signals into an SPI __bus__ configuration**, | ||
+ | - **SD card insert signal**. Our controller should identify if a card has been inserted into the socket, or it has been removed. | ||
+ | - **Write-enable status** of the card. Standard-sized SD cards are equipped with a sliding tab, which can be placed in two positions, one of them marked as **" | ||
+ | |||
+ | Let us examine the SD card modules existing in the market. I have found and used two modules, both having very low prices. Unfortunately, | ||
+ | |||
+ | For the impatient, here is a comparison table: | ||
+ | |||
+ | | ^ Catalex | ||
+ | ^ SD card size | micro SD | Standard SD | | ||
+ | ^ Voltage | ||
+ | ^ Level shifter | ||
+ | ^ SPI | Partial. Does not allow other devices on SPI bus | Exposes SD card pins | | ||
+ | ^ Write-enable detection | No | No | | ||
+ | |||
+ | |||
+ | ===== Catalex ===== | ||
+ | |||
+ | |||
+ | {{arduino: | ||
+ | |||
+ | This module is advertised as an Arduino compatible and SPI compatible module. It can accomodate only microSD cards, so if your project needs to use standard SD cards, this module is not suitable for your purposes. | ||
+ | |||
+ | It contains internally a 5V to 3.3V converter, but it does not expose the 3.3V to the module connectors. The module is equipped with a 74LV125 chip which operates as a level shifter. The module schematic is shown below: | ||
+ | |||
+ | {{arduino: | ||
+ | |||
+ | In all aspects, its design seems superior to the LC Studio module, at least for 5V powered projects. You can wire it to an Arduino, load the libraries and run the examples. It will behave properly and read and write to an SD card. All will be fine....**unless your development project has another SPI module wired to the same controller!!!!** | ||
+ | |||
+ | Examining the board schematic which I have recreated by tracing the wires on the PCB, we find a major flaw in the module design. SPI is supposed to be a multi-participant bus where several " | ||
+ | |||
+ | As a result, the module fails miserably in criterion 4, meaning that the module will not operate if another SPI device shares the same bus. Moreover, it will also block the other device from operating properly. Could we ask a refund from the supplier? Well, probably no. The module specs do not state that the board can co-exist with other SPI devices, only that it can operate by itself in SPI mode, which is actually a function of the SD card. | ||
+ | |||
+ | Could we tamper with the module to make it operate properly? Well, in design terms, yes. After all, the only thing required is to remove pin 13 from ground and connect it to pin 8, which is the module selection signal. (You can see below the schematic of the LC Studio extension circuit to see exactly how it is done.) But in operational terms, this means that we need to desolder very carefully pin 13 of an SMD chip, find a way to raise it in the air without breaking, keep it in the air without touching the board, solder a very small wire to it and solder the other end of the wire on the chip's pin 8. Another " | ||
+ | |||
+ | It would be expected that the manufacturers will have identified this flaw and make the correction, but even after several years I have not yet seen a revised version! | ||
+ | |||
+ | ===== LC Studio ===== | ||
+ | |||
+ | |||
+ | {{arduino: | ||
+ | | ||
+ | |||
+ | This module can accommodate standard sized SD cards, meaning that we can use microSD cards with the help of an adapter. It is powered by a 5V source and contains internally an AMS1117-3.3 linear regulator which converts to 3.3V. A bonus(?) is that the 3.3V output of the converter is available to the module connectors and can be used to power devices external to the module, provided that the consumption does not exceed the AMS1117-3.3 specs. | ||
+ | |||
+ | The 3.3V pin can also be used as an input to the module, if a 3.3V external source is available. The AMS1117-3.3 will not complain if a 3.3V is applied to its output. In such a case, we should make sure that the 5V pin is left floating, without any other power source connected to it. | ||
+ | |||
+ | The board provides only the socket and the voltage converter, while all wiring of the SD card itself and the connector is direct. The few resistors serve only to keep the pins at a steady state and the few capacitors are utilized in the voltage converter. | ||
+ | |||
+ | The module interfaces with the world with a double set of headers. The two pins of each row are wired together, so you can use any of the two. If our project is based on a 3.3V power supply and we do not need to use the level shifter below, we could utilize the double pins to continue our wiring to other SPI devices, connecting the appropriate signals in parallel, except the CS pin of course, since each device should be selected individually. | ||
+ | |||
+ | A schematic of the module can be found online. J1 is the SD card socket and the named signals are connected from the socket to the headers, which is only implied in the schematic. | ||
+ | |||
+ | No copyright is indicated on the schematic. If otherwise, please let me know. | ||
+ | {{arduino: | ||
+ | |||
+ | It is obvious that this SD Card Module complies only with criteria 1 and 2 set in our [[# | ||
+ | |||
+ | Can we expand the module with a level shifter, while at the same time allow the board to work in a multi-participant SPI bus? I have developed the circuit that is depicted in the following diagram for that purpose. We are adding an external chip which operates both as a voltage level shifter and as a chip selector for the SPI bus. This chip is the 74LV125 or 74HCT125N. This is the same chip type used in the Catalex module, in a DIP version, so that we can work with it easily. **(I was not able to find in the market a PDIP 74LV125, so I used an 74HCT125 instead. It is specified at 5V, whereas the 74LV125 works from 2V to 5.5V. Yet it worked, but I cannot guarantee that it will work at all circumstances.)** In this circuit, the wiring allows multiple participation to the SPI bus, because the MISO output (as seen from the module side) is activated only when the controller has explicitly indicated that it intends to communicate with the module, activating the CS pin, which subsequently activates pin 8 of the 74xx125 chip and finally brings the buffer handling the MISO signal out of the high impedance state. Whenever CS is not active, MISO output is kept at the high impedance state, leaving other modules and devices free to use the SPI bus. We could also wire pin 8 to pins 4 and 10 instead of wiring 4 and 10 to ground, but I just wanted to point out in its simplest form the correction that would be required to the Catalex module to make it operate properly. When CS is not active, the SD card by itself ignores the signals in its inputs, so it is OK to have pins 4 and 10 connected to ground. | ||
+ | |||
+ | The chip is powered by the 3.3V which is present in the module connector, so, although we hated it above, we are exploiting it to our benefit and avoid the need of an extra power source. The schematic is shown below: | ||
+ | |||
+ | {{arduino: | ||
+ | |||
+ | I have implemented and tested this configuration where the SD card shared the SPI along with an Ethernet ENC28J60 module. The SD card used pin D4 as Chip Select and the Ethernet module used pin D10. Everything was operating properly. | ||
+ | |||
+ | Of course the addition of one chip and some resistors in a project increases the board space and wiring effort. But, it is the only solution in order to construct a proper module. | ||
+ | |||
+ | ===== Conclusion ===== | ||
+ | |||
+ | Both modules fail to complying with criteria 5 and 6. **Yet, if your project may encounter un-suspected users who believe that setting the " | ||
+ | |||
+ | The Catalex module would be the module of choice for 5V projects with its internal level shifter, **but only if it would be the __only__ single device on the SPI bus** and if only microSD cards are supported. | ||
+ | |||
+ | The LC Studio module is no more than a standard-sized socket and a 3.3V power source. This can be good and bad. Good because you can build whatever you like around the module and even use microSD card, using of course an adapter. Bad, because you need to use discrete components to implement a level shifter. | ||
+ | |||
+ | I have spotted some modules in the internet shops which contain only a socket. If no 3.3V converter is required because there is another such source, probably that would be the best choice. I am afraid that I have not worked with any such module and therefore I cannot express an opinion. | ||
+ | |||
+ | One would reasonably ask, if we build everything externally, why do we need a module and not use directly a simple SD card socket? Check the SD card specifications or visit the [[https:// | ||
+ | |||
+ | |||
+ | ~~DISQUS~~ |