SD_hard_atmega.patch - ska-la/arduino_patches GitHub Wiki
PREREQUISITE. Genuine Arduino IDE's SD library don't allow to use more spi devices at same time. Itself initializes a host behavior and spi bus speed(half available speed). Former it's offered to use a software implementation feature of SD library. It means to involve other pins for spi communication with SD/TF-card(look at SD_soft_atmega328.patch wiki). It's thought that's not a fairly relation to other libraries which use spi bus too. If user wants to use some spi devices at same time it must be implemented and work smoothly. But it's required minor hardware modifications related to MISO signal (look at schematic below).
ESSENTIAL. The patch contains an amendments to SD.cpp and Sd2Card.cpp files, it allows you to use SD card module with another spi modules, like ethernet, on the same pins: 13-SCK, 12-MISO, 11-MOSI (CS pin must be differ for each device). Sentence SPI.begin() must be used outside of any library which uses a spi bus. Example below shows how it works in software and involve two libraries which use a spi bus (SD & EtherEncLib).
#include <SPI.h>
#include <SD.h>
#include <EtherEncLib.h>
...
void setup() {
...
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2); //-- set max spi speed --
SD.begin(4);
lib.begin(ipaddr, macaddr); //EtherEncLib use CS-pin 10 default
...
}
Hardware modifications look like:
THE PATCH IS APPLICABLE TO ALL ARDUINO BOARDS WHICH BASED ON ATmega328/1280/2560 CHIPS. MAY BE OTHER - DON'T TESTED! IT'S APPLICABLE TO ARDUINO IDE 1.0.X VERSIONS ---!!!---
HOWTO. Download the patch, apply it and leave him there for reverse patch in the future:
cd ~/arduino-x.x.x/libraries/
cp ~/Downloads/SD_hard_atmega328_2560_1280.patch .
cd SD/
patch -p1 < ../SD_hard_atmega328_2560_1280.patch
(if you can't do it, download the patched SD.cpp and Sd2Card.cpp, rename (--!!!--DON'T DELETE--!!!--) genuine files and copy patched files on a genuine files places)
After that simply test one of the SD library's examples.
IMPORTANT. It's no need to reverse the patch, only if you feel that something goes wrong. Merely don't forget to use SPI.begin() into setup() of your sketch.
cd ~/arduino-x.x.x/libraries/SD/
patch -p1 -R < ../SD_hard_atmega328_2560_1280.patch