Ethernet Shield + SPI Kommunikation

OP #5006947
Lesenswert?

Hallo Community,

ich habe eine grundlegende Frage zum Prinzip von Arduino und dessen 
Ethernet Shield.

Kann ich den Ethernet Shield und eine SPI Kommunikation gleichzeitig 
durchführen?
Auf den von Arduino vorgesehenen Pins funktioniert das nicht. Wenn ich 
aber eine beliebige Digital OUT nehme und im Programm als MISO/MOSI, 
SCLK, NS definiere, bekomme ich vereinzelt richtige Werte raus.

Wie kann ich am einfachsten mehrere SPI Kommunikation durchführen mi dem 
Ethernet Shield?
Gibt es ein Bauteil, womit ich SPI mit I2C ansteuern kann?
Gast #5006952
Lesenswert?

Karl F. schrieb:
> Kann ich den Ethernet Shield und eine SPI Kommunikation gleichzeitig
> durchführen?

Lese dir deine Frage noch einmal genau durch und frage dich
ob das jemand verstehen soll  kann  muss.

> Kann ich den Ethernet Shield und ... durchführen?

Wer soll was wie kommunizieren?
Gast #5006956
Lesenswert?

Hi

>Wie kann ich am einfachsten mehrere SPI Kommunikation durchführen mi dem
>Ethernet Shield?

Indem jeder SPI-Teilnehmer ein eigens CS-Signal bekommt. MISO/MOSI/CLK 
kommen an alle Teilnehmer.

MfG Spess
OP #5006960
Lesenswert?

Habe zwei Sensoren und einen Ethernet Shield.

Die Werte der Sensoren will ich zu einem Webserver schicken. Da die 
Sensoren nur SPI unterstützen und das Shield meine SPI Leitung 
blockiert, brauche ich eine Alternative.
Ich habe ganz normale 3 Digitale Pins am Arduino zu SPI Pins konuguiert:
( Mosi 32
 Miso 33
 SCLK 31
 CS 30
)
und versucht über diese Leitungen zu kommunizieren. Das hat teils 
richtige Ergebnisse geliefert. Aber macht das so Sinn? Kann ich 
beliebege Pins zu MOSI oder MISO Leitung konfugieren?=
Gast #5006980
Lesenswert?

Hi

>Wie ist dann die NS Leitung vom Ethernet Shield? Müsste ich das auch
>zischen LOW und High wechseln?

Welches Ethernet-Shield hast du?

>Also
>Sensor 1 will Daten senden

Ein Sensor will nicht Senden. Der einzige, der das bestimmt ist der 
Master.

MfG Spess
OP #5007008
Lesenswert?

OP #5007031
Lesenswert?

Jaa, also nochmal:
Ich nutze das Arduino Mega. Wenn ich für meine zwei Sensoren ie Pins 
50-53 nutze, bekomme ich ür die IP-Adresse: 0.0.0.0 angezeigt im 
virteulln Monitor.
Wenn ich nun die Pins umlege auf anderer Digitale Pins und das auch im 
Programm definiere, dann geht das Shield, aber die Daten vom Sensor 
stimmen nicht ganz überein.

Mein aktueller Code dazu:
1
/*
2
  Web Server
3

4
 A simple web server that shows the value of the analog input pins.
5
 using an Arduino Wiznet Ethernet shield.
6

7
 Circuit:
8
 * Ethernet shield attached to pins 10, 11, 12, 13
9
 * Analog inputs attached to pins A0 through A5 (optional)
10

11
 created 18 Dec 2009
12
 by David A. Mellis
13
 modified 9 Apr 2012
14
 by Tom Igoe
15
 modified 02 Sept 2015
16
 by Arturo Guadalupi
17

18
 */
19

20
 
21

22
#include <SPI.h>
23
#include <Ethernet.h>
24
#include <LiquidCrystal_I2C.h>
25
#include <Wire.h>
26
#include <LiquidCrystal.h>
27

28
#define SCLK 53 // Yellow
29
#define SDIO 51 // Red
30
#define NCS 45  // Yellow + tied
31
#define NRESET 42 // Black
32

33
#define REG_PRODUCT_ID 0x00
34
#define REG_REVISION_ID 0x01
35
#define REG_MOTION 0x02
36
#define REG_DELTA_X 0x03
37
#define REG_DELTA_Y 0x04
38
#define REG_SQUAL 0x05
39
#define REG_BURST_MODE 0x63
40
#define REG_PIXEL_GRAB 0x0b
41

42
LiquidCrystal Data_ADNS(28, 30 , 5, 4, 3, 2);
43
LiquidCrystal_I2C  Data_Network(0x27, 2,1,0,4,5,6,7,3,POSITIVE);               //LCD Display definieren und inistialiseren
44

45
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };                          //MAC - Adresse des Internet Shields zuordnen
46
IPAddress ip(192, 168, 1, 177);                                               // freie IP-Adresse im Netzwerk zuordnen
47
EthernetServer server(80);
48

49
void setup() {
50

51
  Serial.begin(9600);
52
  while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only 
53
  }
54

55
  Data_ADNS.begin(16,2);                                                       // LCD Display größe zurodnen
56
  Data_Network.begin(16,2);
57
  Data_Network.clear();                                                        // LCD Grafik löschen
58
  
59
  // start the Ethernet connection and the server:
60
  Ethernet.begin(mac, ip);
61
  server.begin();
62
  Serial.print("server is at ");
63
  Serial.println(Ethernet.localIP());
64
  
65
  Data_Network.setCursor(0,0);
66
  Data_Network.print("IP:");
67
  Data_Network.setCursor(5,0);
68
  Data_Network.print(Ethernet.localIP());
69
}
70

71

72
void loop() 
73
{
74
  dumpDelta();
75
  delay(800);
76
  Data_ADNS.clear();
77
  // listen for incoming clients
78
  EthernetClient client = server.available();
79
  if (client) {
80
    Serial.println("new client");
81
    // an http request ends with a blank line
82
    boolean currentLineIsBlank = true;
83
    while (client.connected()) {
84
      if (client.available()) {
85
        char c = client.read();
86
        Serial.write(c);
87
        // if you've gotten to the end of the line (received a newline
88
        // character) and the line is blank, the http request has ended,
89
        // so you can send a reply
90
        if (c == '\n' && currentLineIsBlank) {
91
          // send a standard http response header
92
          client.println("HTTP/1.1 200 OK");
93
          client.println("Content-Type: text/html");
94
          client.println("Connection: close");  // the connection will be closed after completion of the response
95
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
96
          client.println();
97
          client.println("<!DOCTYPE HTML>");
98
          client.println("<html>");
99
          // output the value of each analog input pin
100
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
101
            int sensorReading = analogRead(analogChannel);
102
            client.print("analog input ");
103
            client.print(analogChannel);
104
            client.print(" is ");
105
            client.print(sensorReading);
106
            client.println("<br />");
107
          }
108
          client.println("</html>");
109
          break;
110
        }
111
        if (c == '\n') {
112
          // you're starting a new line
113
          currentLineIsBlank = true;
114
        } else if (c != '\r') {
115
          // you've gotten a character on the current line
116
          currentLineIsBlank = false;
117
        }
118
      }
119
    }
120
    // give the web browser time to receive the data
121
    delay(1);
122
    // close the connection:
123
    client.stop();
124
    Serial.println("client disconnected");
125
  }
126
}
127

128
void dumpDelta() {
129

130
  char squal = readRegister(0x05);
131
  char motion = readRegister(REG_MOTION); // Freezes DX and DY until they are read or MOTION is read again.
132
  char dx = readRegister(REG_DELTA_X);
133
  char dy = readRegister(REG_DELTA_Y);
134

135
  String string1 = String(motion,BIN);
136

137

138
  
139
  Serial.println("Squal: " + String(squal,DEC));
140
  Serial.println("Motion:    " + String(motion, BIN));
141
  Serial.println("dx:     :" + String(dx, DEC));
142
  Data_ADNS.setCursor(0,0);
143
  Data_ADNS.print("dx:");
144
  Data_ADNS.setCursor(4,0);
145
  Data_ADNS.print(dx,DEC);
146
  Data_ADNS.setCursor(0,1);
147
  Data_ADNS.print("dy:");
148
  Data_ADNS.setCursor(4 ,1);
149
  Data_ADNS.print(dy,DEC);
150
  Serial.println("dy:     :" + String(dy, DEC)); 
151
  Serial.println("     ");
152
  
153
}
154

155

156

157

158

159
void reset() {
160
  pinMode(SCLK, OUTPUT);
161
  pinMode(SDIO, INPUT);
162
  pinMode(NCS, OUTPUT);
163
  pinMode(NRESET, OUTPUT);
164
    
165
  digitalWrite(SCLK, LOW);
166
  digitalWrite(NCS, LOW);
167
  digitalWrite(NRESET, HIGH);
168
  delayMicroseconds(100); 
169
  
170
  // Initiate chip reset
171
  digitalWrite(NRESET, LOW);
172
  pushByte(0xfa);
173
  pushByte(0x5a);
174
  digitalWrite(NRESET, HIGH);
175
  
176
  // Set 1000cpi resolution
177
  digitalWrite(NRESET, LOW);
178
  pushByte(0x0d);
179
  //pushByte(0x01); // 1000cpi
180
  pushByte(0x00); // 500cpi
181
  digitalWrite(NRESET, HIGH);
182
}
183

184

185

186

187
byte pullByte() {
188
  pinMode (SDIO, INPUT);
189

190
  delayMicroseconds(100); // tHOLD = 100us min.
191
  
192
  byte res = 0;
193
  for (byte i=128; i >0 ; i >>= 1) {
194
    digitalWrite (SCLK, LOW);
195
    res |= i * digitalRead (SDIO);
196
    delayMicroseconds(100);
197
    digitalWrite (SCLK, HIGH);
198
  }
199

200
  return res;
201
}
202

203

204

205

206

207

208

209
void pushByte(byte data){
210
  pinMode (SDIO, OUTPUT);
211
  
212
  delayMicroseconds(100); // tHOLD = 100us min.
213
  
214
  for (byte i=128; i >0 ; i >>= 1) {
215
    digitalWrite (SCLK, LOW);
216
    digitalWrite (SDIO, (data & i) != 0 ? HIGH : LOW);
217
    delayMicroseconds(100);
218
    digitalWrite (SCLK, HIGH);
219
    
220
    //Serial.print((data & i) != 0 ? HIGH : LOW, BIN);
221
  }
222
  //Serial.println("");
223
}
224

225
byte readRegister(byte address) {
226
  address &= 0x7F; // MSB indicates read mode: 0
227
  
228
  pushByte(address);
229
  
230
  byte data = pullByte();
231
  
232
  return data;  
233
}
234

235
void writeRegister(byte address, byte data) {
236
  address |= 0x80; // MSB indicates write mode: 1
237
  
238
  pushByte(address);
239
  
240
  delayMicroseconds(100);
241
  
242
  pushByte(data);
243

244
  delayMicroseconds(100); // tSWW, tSWR = 100us min.
245
}

Also Ziel soll es sein, dass ethernetShield und die beiden anderen 
Sensoren zu verwenden. Bzw Wenn das EthernetShield mit SPI kommuniziert, 
wie kann ich die NS Leitung auf High setzen, wenn der master von den 
Sesnoren Daten vrlangt..

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren