Posted by : MC 11 Temmuz 2015 Cumartesi



Everybody knows,
Official arduino ethernet shiled also has a SD card slot.
So many people has some problems about using these at the same time.

What is the main problem?

In SPI, the following connections are used:
MISO (Master In Slave Out) - a data line for sending data from the slave to the master
MOSI (Master Out Slave In) - a data line for sending data from the master to the slave
SCK (Serial Clock) - a clock generated by the master for clocking the bits on MISO and MOSI
SS (Slave Select) - a data line from the master to a particular slave.

There is one SS for every slave device. MISO, MOSI, and SCK are shared between all the devices on the bus.

Pin 4 is SS for the SD card interface while pin 10 is SS for the ethernet controller.So each time we can only get communication with one chip (SD or Ethernet)

What is the solution:

First of all, in the setup loop you have to init your Sd card then ethernet.

After setup,you can use each one (Sd card or ethernet functions) by selecting its own chip (enable pin4 or pin 10).

#define SS_SD_CARD   4
#define SS_ETHERNET 10

void setup() {
    // ...
    pinMode(SS_SD_CARD, OUTPUT);
    pinMode(SS_ETHERNET, OUTPUT);
    digitalWrite(SS_SD_CARD, HIGH);  // SD Card not active
    digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
    // ...
}

void scCardCode() {
    // ...
    digitalWrite(SS_SD_CARD, LOW);  // SD Card ACTIVE
    // code that sends to the sd card slave device over SPI
    // using SPI.transfer() etc.
    digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
    // ...
}

void ethernetCode() {
    // ...
    digitalWrite(SS_ETHERNET, LOW);  // Ethernet ACTIVE
    // code that sends to the ethernet slave device over SPI
    // using SPI.transfer() etc.
    digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
    // ...
}

yorumlarınız bizim için önemli

Bültene abone ol | Yorumlara abone ol

ELEKTRO BLOGGER A HOŞGELDINIZ

ARAMA YAP

EN COK OKUNANLAR

- Copyright © ELEKTRO-BLOGGER Blogger