I have already printed my PCB with SD card module, ethernet card module ENC28J60 and Arduino MEGA. SD has CS pin 4 and ethernet CS pin 53, I have tested SD and it is working fine but when I try to use ethernet it is not working unless if I remove SD module from PCB. SD module is causing problems to ethernet without using it. I have tested ethercard library too and it is the same. Why is this happening, and how to fix it?
The code I run:
/**************************************************************
* For this example you need UIPEthernet library:
* https://github.com/ntruchsess/arduino_uip
*
* Wire it up:
VCC - 3.3V
GND - GND
SCK - Pin 52
SO - Pin 50
SI - Pin 51
CS - Pin 53
INT - PIN 2 (I don't use it because it is working without it)
*
*
**************************************************************/
#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneDefines.h>
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
#include <CayenneEthernetClient.h>
#include <SPI.h>
char token[] = "TOKEN"; //NOT MY TOKEN
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}
void loop()
{
Cayenne.run();
}
Too little code there to see what is happening, for me anyway.
Can't tell for instance if the slave selects are only being enabled one at a time.
No schematic, so can't tell if you buffered MISO coming back from the SD card to keep it off the bus while other devices are active.
Can't tell if you're running at 5V and buffering SCK/MOSI/slave selects down to 3.3V, or if you're using a '2560V and running everything at 3.3V.
Just one big guessing game until you provide more data.
UPDATE: It works if I both Vcc are 5V or 3.3V but it is not recommended
Ethercard using 3.3V while sd card is using 5V. This is full code, I dont use sd on this sketch and Ethernet still not working. Both modules are parallel connected to MOSI MISO SCK.
Onother code I use with same results
// Ping a remote server, also uses DHCP and DNS.
// 2011-06-12 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
ether.printIp(">>> ping from: ", ptr);
}
void setup () {
Serial.begin(57600);
Serial.println("\n[pings]");
if (ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
#if 1
// use DNS to locate the IP address we want to ping
if (!ether.dnsLookup(PSTR("www.google.com")))
Serial.println("DNS failed");
#else
ether.parseIp(ether.hisip, "74.125.77.99");
#endif
ether.printIp("SRV: ", ether.hisip);
// call this to report others pinging us
ether.registerPingCallback(gotPinged);
timer = -9999999; // start timing out right away
Serial.println();
}
void loop () {
word len = ether.packetReceive(); // go receive new packets
word pos = ether.packetLoop(len); // respond to incoming pings
// report whenever a reply to our outgoing ping comes back
if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
Serial.print(" ");
Serial.print((micros() - timer) * 0.001, 3);
Serial.println(" ms");
}
// ping a remote server once every few seconds
if (micros() - timer >= 5000000) {
ether.printIp("Pinging: ", ether.hisip);
timer = micros();
ether.clientIcmpRequest(ether.hisip);
}
}
Output on serial monitor stucked on: [pings]
It works too if sd card is removed.
Where is the schematic of YOUR board/setup? You've posted a picture of someone else's generic SPI wiring (and one labeled "poor SPI bus design" no less!)
Explain what you're talking about with 5v vs 3.3v - easiest way is probably WITH THE SCHEMATIC!