Hello,
I'm encountering a problem with my setup using a MAX31865 RTD sensor on an Arduino Mega 2560 with an Ethernet Shield (W5100).
Previously, on older Arduino Mega boards, I was able to use hardware SPI for the MAX31865 and the Ethernet Shield without issues. However, on the new Arduino Mega 2560 boards I've purchased recently, the hardware SPI communication with the MAX31865 stops working.
When I switch to using software SPI, the MAX31865 operates correctly. But as soon as I call Ethernet.begin(mac, ip);
to initialize the Ethernet Shield, the MAX31865 stops functioning.
Another unusual detail I noticed is that software SPI communication fails if the sensor’s SDI pin is connected to digital pin 51. When SDI is connected to any other pin, it works as expected.
I have double-checked the hardware connections (even swapping SDI and SDO on the MAX31865) but the problem persists.
Has anyone encountered a similar issue or found a solution to restore reliable hardware SPI communication on the new boards? Any help would be appreciated.
#include <TimeLib.h>
#include <Adafruit_MAX31865.h>
#include <pt100rtd.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <avr/wdt.h>
//sdo=50,sdi=51,clk=52
//MOSI= SDO = 50
//MISO= SDI = 51
//CLK = 52
//SDA=20
//SCL=21
Adafruit_MAX31865 max_1a = Adafruit_MAX31865(48);
Adafruit_MAX31865 max_2a = Adafruit_MAX31865(46);
Adafruit_MAX31865 max_3a = Adafruit_MAX31865(44);
Adafruit_MAX31865 max_4a = Adafruit_MAX31865(42);
Adafruit_MAX31865 max_5a = Adafruit_MAX31865(40);
#define RREF 430.0
#define C2F(c) ((9 * c / 5) + 32)
pt100rtd PT100 = pt100rtd() ;
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0xA0, 0x33};
IPAddress ip(xxx,xxx,xxx,202); //put your ip here
unsigned int puerto = 3000;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
String dataReq;
EthernetUDP udp;
void setup() {
max_1a.begin(MAX31865_3WIRE);
max_2a.begin(MAX31865_3WIRE);
max_3a.begin(MAX31865_3WIRE);
max_4a.begin(MAX31865_3WIRE);
max_5a.begin(MAX31865_3WIRE);
Serial.begin(9600);
wdt_disable();
delay(3000);
wdt_enable(WDTO_4S);
Ethernet.begin(mac, ip);
udp.begin(puerto);
delay(1500);
}
void loop() {
if (udp.parsePacket() > 0) {
udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
String datReq(packetBuffer);
Serial.println(datReq);
uint16_t rtd_1a, rtd_2a, rtd_3a, rtd_4a, rtd_5a,ohmsx100;
uint32_t dummy ;
float ohms, Tlut, T ;
rtd_1a = max_1a.readRTD();
rtd_2a = max_2a.readRTD();
rtd_3a = max_3a.readRTD();
rtd_4a = max_4a.readRTD();
rtd_5a = max_5a.readRTD();
uint16_t vector[5]={rtd_1a,rtd_2a,rtd_3a,rtd_4a,rtd_5a};
udp.beginPacket(udp.remoteIP(), udp.remotePort());
for (int i = 0; i < 5; i = i + 1) {
dummy = ((uint32_t)(vector[i] << 1)) * 100 * ((uint32_t) floor(RREF)) ;
dummy >>= 16 ;
ohmsx100 = (uint16_t) (dummy & 0xFFFF) ;
Tlut = PT100.celsius(ohmsx100) ;
udp.print(Tlut, 3);
if (i < 4) {
udp.print(",");
}
}
udp.println("");
udp.endPacket();
}
wdt_reset();
}
Thank you!