• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
2 slave na SPI
#1
Połączyłam Arduino UNO, RFID MFRC522 oraz Ethernet ENC28J60. Osobno wszystko działa bez zarzutu. Problem pojawia gdy chcę ich używać razem. ENC28J60 działa, MFRC nie. Nie wiem czy to problem kodu, czy może sprzętu.

Kod:
#include <UIPEthernet.h> // Used for Ethernet
#include <SPI.h>
#include <RFID.h>

#define SS_PIN 6
#define RST_PIN 9
RFID rfid (SS_PIN, RST_PIN);
// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };                                      
// For the rest we use DHCP (IP address and such)

EthernetClient client;
char server[] = "www.strona.pl"; // IP Adres (or name) of server to dump data to
int  interval = 5000; // Wait between dumps
   
   int serNum0;
   int serNum1;
   int serNum2;
   int serNum3;
   int serNum4;
   
   String numer;
   String numer0;
   String numer1;
   String numer2;
   String numer3;
   String numer4;

void setup() {
 
 pinMode(6, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(2, OUTPUT);
 digitalWrite(6, HIGH);
 digitalWrite(10, HIGH);
 
 Serial.begin(9600);
 SPI.begin();
 
 digitalWrite(10, LOW);
 
 Ethernet.begin(mac);
   
 digitalWrite(10, HIGH);
 digitalWrite(6, LOW);
 
 rfid.init();
 
 digitalWrite(6, HIGH);
 digitalWrite(10, LOW);
 
 Serial.print("IP Address        : ");
 Serial.println(Ethernet.localIP());
 Serial.print("Subnet Mask       : ");
 Serial.println(Ethernet.subnetMask());
 Serial.print("Default Gateway IP: ");
 Serial.println(Ethernet.gatewayIP());
 Serial.print("DNS Server IP     : ");
 Serial.println(Ethernet.dnsServerIP());
}

void loop() {
 
   digitalWrite(6, HIGH);
   digitalWrite(10, LOW);
                 
 // if you get a connection, report back via serial:
 if (client.connect(server, 80)) {
   Serial.println("-> Connected");
   
     digitalWrite(10, HIGH);
     digitalWrite(6, LOW);
     
   
   if (rfid.isCard()) {
       if (rfid.readCardSerial()) {
           if (rfid.serNum[0] != serNum0
               && rfid.serNum[1] != serNum1
               && rfid.serNum[2] != serNum2
               && rfid.serNum[3] != serNum3
               && rfid.serNum[4] != serNum4
           ) {
               serNum0 = rfid.serNum[0];
               serNum1 = rfid.serNum[1];
               serNum2 = rfid.serNum[2];
               serNum3 = rfid.serNum[3];
               serNum4 = rfid.serNum[4];
               
               numer0 = String(serNum0);
               numer1 = String(serNum1);
               numer2 = String(serNum2);
               numer3 = String(serNum3);
               numer4 = String(serNum4);
               numer= numer0 + numer1 + numer2 + numer3 + numer4;            
               Serial.println(numer);
             
              digitalWrite(6, HIGH);
              digitalWrite(10, LOW);
             
             // Make a HTTP request:
             client.print( "GET /test/add_data.php?");
             client.print("serial=");
             client.print( numer );
             client.println( " HTTP/1.1");
             client.print( "Host: " );
             client.println(server);
             client.println( "Connection: close" );
             client.println();
             client.println();
             client.stop();
             Serial.println("ok");
             digitalWrite(2, HIGH);
             delay(1000);            
             digitalWrite(2, LOW);
         
       }}}
                 digitalWrite(10, HIGH);
                 digitalWrite(6, LOW);
               rfid.halt();
 }
 else {
   // you didn't get a connection to the server:
   Serial.println("--> connection failed/n");
 }

}

Może ktoś znajdzie błąd w kodzie, albo podpowie jak sprawdzić czy moduły poprawnie korzystają z SPI
 
Odpowiedź
#2
Dlaczego sam zmieniasz stan linii SS dla poszczególnych urządzeń?
Gdy działają osobno to piny SS są takie jak w programie?
Pomagam za darmo więc szanuj mój czas.
Wklejaj tekst a nie jego zdjęcie.
Nie pisz następnego postu jak nie odpowiedziałeś na poprzedni.
Jak mądrze zadawać pytania
 
Odpowiedź
#3
(30-11-2016, 13:23)namok napisał(a): Dlaczego sam zmieniasz stan linii SS dla poszczególnych urządzeń?
Gdy działają osobno to piny SS są takie jak w programie?

Zmieniam, bo tak było w przykładach na których się opierałam, jak nie zmieniam też nie działa.

Tak, piny są takie same jak w tym programie.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości