I appreciate your input. As per your advice, II am abandoning the SPI0 and SPI1 attempt. I am trying to get the DW1000 radio and WizNet W5500 Ethernet controller to share SPI0. Both SPI devices work fine independently. Together I get no Compiler errors and no radio or Ethernet data. Please see code below, thank you!
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
// connection pins#define SHIELD_TYPE USING_W5500 // or USING_W5100, USING_W5200, etc.
#include "DW1000.h"
#include "DW1000Ranging.h"
const int ETH_CS_PIN = 22;
///////////////////////////////////
SPISettings dw1000set(20000000,MSBFIRST,SPI_MODE0);
SPISettings w5500set(20000000,MSBFIRST,SPI_MODE0);
const uint8_t PIN_RST = 9; // reset pin
const uint8_t PIN_IRQ = 2; // irq pin
const uint8_t PIN_SS = SS; // spi select pin
/////////////////////
volatile boolean received = false;
volatile boolean error = false;
volatile int16_t numReceived = 0; // todo check int type
String message;
int deviceAddress;
int x = 0;
////////////////////////
// Enter a MAC address and IP address
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 10, 177);
IPAddress remote(192, 168, 10, 129);
unsigned int localPort = 8888; // local port to listen on
unsigned int remotePort = 8888;
EthernetUDP Udp;
//////////////////////
void setup() {//////////////////////////////////////////////////////////////
Serial.begin(9600);
delay(1000);
SPI.setSCK(18);///SLK
SPI.setTX(19); // MOSI
SPI.setRX(16); // MISO
SPI.begin(true);
pinMode(PIN_SS,OUTPUT);
digitalWriteFast(PIN_SS, HIGH);
pinMode(ETH_CS_PIN,OUTPUT);
digitalWriteFast(ETH_CS_PIN, HIGH);
//DW1000.newConfiguration();
messageSetup();
delay(1000);
//init the configuration
DW1000Ranging.initCommunication(PIN_RST, PIN_SS, PIN_IRQ); //Reset, CS, IRQ pin
//define the sketch as anchor. It will be great to dynamically change the type of module
DW1000Ranging.attachNewRange(newRange);
DW1000Ranging.attachNewDevice(newDevice);
DW1000Ranging.attachInactiveDevice(inactiveDevice);
//Enable the filter to smooth the distance
//DW1000Ranging.useRangeFilter(true);
//we start the module as a tag
DW1000Ranging.startAsAnchor("9C:00:22:EA:82:60:3B:7D", DW1000.MODE_LONGDATA_RANGE_ACCURACY);
delay(100);
/////////////////////////////////////////////
//while (!Serial);
Ethernet.init(ETH_CS_PIN);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.print("IP: ");
Serial.println(Ethernet.localIP());
delay(100);
/////////////////////////////////////////////////////////////////////////
}
void loop() {
DW1000Ranging.loop();
if(x==133000){
messageReceived();
x = -133000;
}else{
//DW1000Ranging.loop();
x++;
}
}
void newRange() {
SPI.beginTransaction(dw1000set);
digitalWriteFast(PIN_SS, LOW);
Serial.print("from: ");
Serial.print(DW1000Ranging.getDistantDevice()->getShortAddress(), HEX);
deviceAddress = (DW1000Ranging.getDistantDevice()->getShortAddress(), HEX);
Serial.print("\t Range: ");
Serial.print(DW1000Ranging.getDistantDevice()->getRange());
Serial.print(" m");
Serial.print("\t RX power: ");
Serial.print(DW1000Ranging.getDistantDevice()->getRXPower());
Serial.println(" dBm");
digitalWriteFast(PIN_SS, HIGH);
SPI.endTransaction();
delay(1000);
///SPI SWITCH//////////////////////////////////////
SPI.beginTransaction(w5500set);
digitalWriteFast(ETH_CS_PIN, LOW);
Udp.beginPacket(remote, remotePort);
Udp.write(deviceAddress);
Udp.write(DW1000Ranging.getDistantDevice()->getRange());
Udp.write(DW1000Ranging.getDistantDevice()->getRXPower());
Udp.endPacket();
digitalWriteFast(ETH_CS_PIN, HIGH);
SPI.endTransaction();
delay(1000);
}//////////////////////////////////////////////////////
void newDevice(DW1000Device device) {
SPI.beginTransaction(dw1000set);
digitalWriteFast(PIN_SS, LOW);
Serial.print("ranging init; 1 device added ! -> ");
Serial.print(" short:");
Serial.println(device->getShortAddress(), HEX);
int addedDevice = (device->getShortAddress(), HEX);
SPI.endTransaction();
digitalWriteFast(PIN_SS, HIGH);
/////////////////////////
SPI.beginTransaction(w5500set);
digitalWriteFast(ETH_CS_PIN, LOW);
Udp.beginPacket(remote, remotePort);
Udp.write(deviceAddress);
Udp.write(addedDevice);
Udp.endPacket();
SPI.endTransaction();
digitalWriteFast(ETH_CS_PIN, HIGH);
/////////////////////////
}
void inactiveDevice(DW1000Device* device) {
SPI.beginTransaction(dw1000set);
digitalWriteFast(PIN_SS, LOW);
Serial.print("delete inactive device: ");
Serial.println(device->getShortAddress(), HEX);
int inactiveDevice = (device->getShortAddress(), HEX);
digitalWriteFast(PIN_SS, HIGH);
SPI.endTransaction();
/////////////////////////
SPI.beginTransaction(w5500set);
digitalWriteFast(ETH_CS_PIN, LOW);
Udp.beginPacket(remote, remotePort);
Udp.write(deviceAddress);
Udp.write(inactiveDevice);
Udp.endPacket();
SPI.endTransaction();
digitalWriteFast(ETH_CS_PIN, HIGH);
/////////////////////////
}
void messageSetup(){///////////////////////////////////////////////////////
Serial.println(F("### DW1000-arduino-receiver-test ###"));
// initialize the driver
DW1000.begin(PIN_IRQ, PIN_RST);
DW1000.select(PIN_SS);
Serial.println(F("DW1000 initialized ..."));
// general configuration
DW1000.newConfiguration();//////
DW1000.setDefaults();
DW1000.setDeviceAddress(6);
DW1000.setNetworkId(10);
// DW1000.enableMode(DW1000.MODE_LONGDATA_RANGE_LOWPOWER);
DW1000.commitConfiguration();
Serial.println(F("Committed configuration ..."));
// DEBUG chip info and registers pretty printed
char msg[128];
DW1000.getPrintableDeviceIdentifier(msg);
Serial.print("Device ID: "); Serial.println(msg);
DW1000.getPrintableExtendedUniqueIdentifier(msg);
Serial.print("Unique ID: "); Serial.println(msg);
DW1000.getPrintableNetworkIdAndShortAddress(msg);
Serial.print("Network ID & Device Address: ");
Serial.println(msg);
DW1000.getPrintableDeviceMode(msg);
Serial.print("Device mode: "); Serial.println(msg);
// attach callback for (successfully) received messages
delay(100);
DW1000.attachReceivedHandler(handleReceived);/////////
delay(100);
DW1000.attachReceiveFailedHandler(handleError);
delay(100);
DW1000.attachErrorHandler(handleError);
// start reception
delay(10000);
receiver();
}///////////////////////////////////////////////////////////////////////////
void handleReceived() {
// status change on reception success
received = true;
}
void handleError() {
error = true;
}
void receiver() {
DW1000.newReceive();
DW1000.setDefaults();
// so we don't need to restart the receiver manually
DW1000.receivePermanently(true);
DW1000.startReceive();
}
void messageReceived(){
SPI.beginTransaction(dw1000set);
digitalWriteFast(PIN_SS, LOW);
Serial.println("");
Serial.println("/////////");
DW1000.getData(message);
Serial.println(message);
Serial.println("/////////");
Serial.println("");
received = false;
SPI.endTransaction();
digitalWriteFast(PIN_SS, HIGH);
}