Hi all,
I've been trying to connect an ENC28J60 ánd an SD cardreader module to an Arduino Nano on the SPI bus. Both modules work fine but only when the other module is not connected.
Then I found this: SOLVED. Nrf24 (Mirf lib) + Micro SD-card works OK together
I'm pretty sure I have the same problem. The SD card module is probably not playing nice on the SPI bus. The thread is marked as "SOLVED" but not really.
What I've tried:
-- desoldering an SMD pin en bridging it, that ended in one big blob of solder on all the pins and a ruined SD card reader I'm not going to try that again.
-- Using "SPI.transfer(0);" after initializing the SD card as suggested in: SOLVED. Nrf24 (Mirf lib) + Micro SD-card works OK together - #7 by chucktodd
Someone suggested using an "Adafruit 254 micro Sd breakout board" that should work out of the box
What is going on and how can I use both an enc28J60 ánd an SD card reader? What card reader should I get? What libraried do I use? Sorry but this is kinda frustrating.
Any help would be most welcome!
This is my curtrent setup and below is my current code:
// ETHERNET ==============================================================
#include <EtherCard.h>
#define TCP_FLAGS_FIN_V 1
#define TCP_FLAGS_ACK_V 0x10
static byte myip[] = { 192,168,1,177 };
static byte gwip[] = { 192,168,1,1 };
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x39 };
byte Ethernet::buffer[200]; // tcp ip send and receive buffer
const char indexPage[] PROGMEM = // Hello world webpage
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html>"
"<body>"
"<h3>Hello from webserver</h3>"
"</body>"
;
// SD CARD ===============================================================
#include <SPI.h>
#include <SD.h>
Sd2Card card; // set up variables using the SD utility library functions
SdVolume volume;
SdFile root;
const int chipSelect = 9; // change this to match your SD shield or module;
// SETUP =================================================================
void setup(){
Serial.begin(115200);
while (!Serial);
Serial << "Hello" << endl;
// SD CARD =============
if (!card.init(SPI_HALF_SPEED, chipSelect)) { // Initialize and check SD card
Serial << "SD initialisation failed" << endl;
}else{
Serial << "Wiring is correct and a card is present." << endl;
}
SPI.transfer(0); // just activate the SPI SCK for 8 pulses, none of the devices on the bus
// have their CS pin low, so there should be no reaction, but sometimes the SD card does not release
// the MISO pin until it sees a few clocks, so by sending a null without any CS driven low it tends to
// 'clear' the SPI bus
if (!volume.init(card)) { // Try to open the 'volume'/'partition' - it should be FAT16 or FAT32
Serial << "Could not find FAT16/FAT32 partition" << endl;
}
// ETHERNET ============
ether.begin(sizeof Ethernet::buffer, mymac , SS); // Change 'SS' to Slave Select pin if not using default
ether.staticSetup(myip, gwip);
Serial << "end of setup" << endl;
} // end setup
// LOOP ==================================================================
void loop(){
word pos = ether.packetLoop(ether.packetReceive());
if (pos){ // check if valid tcp data is received
char* data = (char *) Ethernet::buffer + pos;
Serial << data << endl;
if (strncmp("GET / ", data, 6) == 0){
ether.httpServerReplyAck(); // send ack to the request
memcpy_P(ether.tcpOffset(), indexPage, sizeof indexPage); // send first packet and not send the terminate flag
ether.httpServerReply_with_flags(sizeof indexPage - 1,TCP_FLAGS_ACK_V|TCP_FLAGS_FIN_V);
}
}
} // end loop```