I try, buut still can't make the ISP works

Hi,
I have a project who use the following device:
Inboard WiFi
a vbus water heater on serial1
3 Adafruit_MAX31865 on supose to be the SPI, but atually on port 11,12,13

My program is crashing very well (even watchdog is nt working) at some point between 1h to 13h!
If I don0t use the Serial 1 port, the program crash in 13h or so! I can't tell what is causing the crash.
If I use everything it crash after a 1h.

What I find is the WiFi at some time is loosing the com with the AVR, I got a WiFi Status of 255 no module.
So I decide to start simple on another device, just Arduino WiFi v2, 1 Adafruit_MAX31865 and the WiFi NINA.

But then problem arise,
On the documentation I read 'https://www.arduino.cc/en/Guide/ArduinoUnoWiFiRev2' it sayid that the ISP is on ICSP and not on port 10-13, I was never able to make that true!

So before going further is that true or not, and if so why I cant make my MAX31865 not working on this ICSP port?
And what are the CS port for the other module on ISP (WiFi and IMU, and crpyto chip)

here is my code, now I didn't code the WiFi part.

#include <Adafruit_MAX31865.h>
#include <WiFiNINA.h>
#include <utility/wifi_drv.h>

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 room_temp = Adafruit_MAX31865(8);

float room_temp_mesure;

#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
#define RNOMINAL  100.0

void setup() {
  Serial.begin(57600);
  Serial.println(F("Room temperature"));

  // put your setup code here, to run once:
  room_temp.begin(MAX31865_2WIRE);

}

void loop() {
  room_temp_mesure = room_temp.temperature(RNOMINAL, RREF);

  Serial.print( "Room temp: ");
  Serial.println(room_temp_mesure, 1);

 // Check and print any faults
  uint8_t fault = room_temp.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold"); 
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold"); 
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias"); 
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage"); 
    }
    room_temp.clearFault();
  }
  Serial.println();

  delay(1000);

}

Thanks for any input.

So in the attached code, it seems all you have connected is the IDE and RTDs.

If so I would put a fixed resistor right at the MAX boards, or an RTD right at the board. The goal is to eliminate any "antenna" effect from long RTD leads.

Run the board and see what goes wrong.

Oh and does your connected computer have a power saving program running? i.e. does it shutdown when not being typed on.

Hey John,
So I find why in this code I was not able to make it work with the usal ICSP connector.
The picture of the connector was upside down :wink:
So the MISO was actually the GND :wink:

So this code is working with the wifi since 24h, I will see if it crash.

As for my other project I can't put the code here, because it's split in 5 files, so I have to look if I can upload a zip file with all of it inside.

But I jst try with the RTD on the ICSP connector, and as soon as I get something from the srial1 it crash my whole board, and the WiFi is gone as code 255.

Here is the code that crash (entering the readVbus

// Settings for the VBus decoding
#define Sync  0xAA  // Synchronisation bytes
#define FrameLength 6   // Framelength
#define FrameOffset 10  // Offset start of Frames
#define FrameSeptet 4   // Septet byte in Frame
#define SENSORNOTCONNECTED 8888 // Sometimes this might be 888 instead.

/*
67. DFA (0x0010) <= SOLTOP DeltaSol S2/S3 (0x7731)
Offset Size Mask             Name                                                                  Factor Unit
0                             2                                             Temperature sensor 1 0.1          °C
2                             2                                             Temperature sensor 2 0.1          °C
Frame 2
4                             2                                             Temperature sensor 3 0.1          °C
6                             2                                             Temperature sensor 4 0.1          °C
Frame 3
8                             2                                             Temperature sensor 5 0.1          °C
10                           2                                              Temperature sensor 6 0.1          °C
Frame 4
12                           2                                              Temperature sensor 7 0.1          °C
14                           2                                              Temperature sensor 8 0.1          °C
Frame 5
16                           1                                              Pump speed R1                                               1                             %
17                           1                                              Pump speed R2                                               1                             %
18                           1                                              Pump speed R3                                               1                             %
19                           1                                              Relay byte                                                         1
Frame 6
20                           2                                              Heat                                                                     1                             Wh
22                           2                                              Heat                                                                     1000      Wh
Frame 7
24                           2                                              Heat                                                                     1000000 Wh
26                           1                                              Scheme                                                                              1
*/

unsigned char Buffer[100];
volatile unsigned char Bufferlength;

void initVbus(){
  Serial1.begin(9600);
  Serial.println(F("vBus Serial open"));

  solar_temp=0.0; // S1
  ecs_low_temp=0.0; // S2
  ecs_high_temp=0.0; // S3
  solar_ret_temp=0.0; // S4
}

bool readVbusValue() {
    char c;
    bool start,stop,quit;

    start = true;
    stop = false;
    quit = false;
    Bufferlength=0;
    lastTimeTimer = 0;
    lastTimeTimer = millis();
    memset(0, Buffer, sizeof(Buffer));

  Serial.println(F("vBus read"));

  while ((!stop) and (!quit))  {
    if (Serial1.available()) {
      c=Serial1.read();

      if (c == Sync || c==0xFFFFFFAA) {
        if (start) {
          start=false;
          Bufferlength=0;
        } else {
          if (Bufferlength<20) {
            lastTimeTimer = 0;
            lastTimeTimer = millis();
            Bufferlength=0;
          } else
            stop=true;
          }
        }
      if ((!start) and (!stop)) {
        Buffer[Bufferlength]=c;
        Bufferlength++;
      }
    } // end if mySerial.available
    if ((timerInterval > 0) &&  (millis() - lastTimeTimer > timerInterval ) ) {
      quit=true;
    }
  } // end while loop

  lastTimeTimer = 0;

Serial.println( F("Buffer: "));
for( int i=0;i <= Bufferlength; i++ ) {
  Serial.print( Buffer[i], HEX);
  Serial.print( " " );
}
Serial.println("");

  if (!quit) {
    Destination_address = Buffer[2] << 8;
    Destination_address |= Buffer[1];
    Source_address = Buffer[4] << 8;
    Source_address |= Buffer[3];
    ProtocolVersion = (Buffer[5]>>4) + (Buffer[5] &(1<<15));

    Command = Buffer[7] << 8;
    Command |= Buffer[6];
    Framecnt = Buffer[8];
    Checksum = Buffer[9];  //TODO check if Checksum is OK

    Serial.println(F("---------------"));
    Serial.print(F("Destination: "));
    Serial.println(Destination_address, HEX);
    Serial.print(F("Source: "));
    Serial.println(Source_address, HEX);
    Serial.print(F("Protocol Version: "));
    Serial.println(ProtocolVersion);
    Serial.print(F("Command: "));
    Serial.println(Command, HEX);
    Serial.print(F("Framecount: "));
    Serial.println(Framecnt);
    Serial.print(F("Checksum: "));
    Serial.println(Checksum);
    Serial.print(F("Bufferlength: "));
    Serial.println(Bufferlength);
    Serial.println(F("---------------"));

 /*
15:38:33.340 -> Destination: 10
15:38:33.340 -> Source: 7731
15:38:33.340 -> Protocol Version: 1
15:38:33.340 -> Command: 100
15:38:33.340 -> Framecount: 7
15:38:33.378 -> Checksum: 47
15:38:33.378 -> Bufferlength: 52  Sometime 38 why
*/

  // Only analyse Commands 0x100 = Packet Contains data for slave
  // with correct length = 10 bytes for HEADER and 6 Bytes  for each frame
  // Buffer length has to be 52 to be correct (7*6=42 + 10=52)

//    if ((Command==0x0100) and (Bufferlength==10+Framecnt*6)) {
    if ( (Command==0x0100) ) {
      //Only decode the data from the correct source address
      //(There might be other VBus devices on the same bus).
      decodeVbusFrame(Buffer);

      Serial.println(F("------Values------"));
      Serial.print(F("Solar : "));
      Serial.println(solar_temp);
      Serial.print(F("ECS Low: "));
      Serial.println(ecs_low_temp);
      Serial.print(F("ECS High: "));
      Serial.println(ecs_high_temp);
      Serial.print(F("Solar return: "));
      Serial.println(solar_ret_temp);
 
      Serial.print(F("Pump speed1: "));
      Serial.println(PumpSpeed1, HEX);
      Serial.print(F("Pump speed2: "));
      Serial.println(PumpSpeed2, HEX);
      Serial.print(F("Pump speed3: "));
      Serial.println(PumpSpeed3, HEX);
      Serial.print(F("Relay: "));
      Serial.println(Relay, HEX);
      Serial.print(F("Heat: "));
      Serial.println(HeatQuantity);
      Serial.print(F("Scheme: "));
      Serial.println(Scheme, HEX);      


 /*
14:56:55.174 -> Pump speed1: 64
14:56:55.174 -> Pump speed2: 64
14:56:55.174 -> Pump speed3: 0
14:56:55.174 -> Relay: 6

32'390,643
afficher 32 390 KWH
*/
    } else {
      Serial.println(F("Error vBus "));
      return false;
     }
  }
  return true;
}

void decodeVbusFrame( unsigned char *frame ){
  int FO;
//  Serial.println(F("Now decoding for 0x7731"));

  FO=FrameOffset;
  Septet=frame[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);

  solar_temp = CalcTemp(frame[FO+1], frame[FO]);
  ecs_low_temp = CalcTemp(frame[FO+3], frame[FO+2]);
/*
18:50:22.981 -> Solar : 7.80
18:50:22.981 -> ECS Low: 26.30
*/
  //*******************  Frame 2  *******************
  FO=FrameOffset+FrameLength;
  Septet=Buffer[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);

  ecs_high_temp = CalcTemp(frame[FO+1], frame[FO]);
  solar_ret_temp = CalcTemp(frame[FO+3], frame[FO+2]);

/*
18:50:22.981 -> ECS High: 44.80
18:50:22.981 -> Solar return: 21.10
*/
  //*******************  Frame 3  *******************
  FO=FrameOffset+FrameLength+2;
  Septet=Buffer[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);
/*
Serial.print("Temp5 : ");
Serial.println(CalcTemp(frame[FO+1], frame[FO]));
Serial.print("Temp6 : ");
Serial.println(CalcTemp(frame[FO+3], frame[FO+2]));
*/
//*******************  Frame 4  *******************
  FO=FrameOffset+FrameLength+3;
  Septet=Buffer[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);

/*
Serial.print("Temp7 : ");
Serial.println(CalcTemp(frame[FO+1], frame[FO]));
Serial.print("Temp8 : ");
Serial.println(CalcTemp(frame[FO+3], frame[FO+2]));
*/
//*******************  Frame 5  *******************
  FO=FrameOffset+FrameLength*4;
  Septet=Buffer[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);

  PumpSpeed1 = (frame[FO] & 0X7F);
  PumpSpeed2 = (frame[FO+1] & 0X7F);
  PumpSpeed3 = (frame[FO+2] & 0X7F);
  Relay = frame[FO+3];
  if( Relay == 6 ) Relay = 1; // 2 chauffage bas
/*
Serial.println( F("Frame 5"));
Serial.println( frame[FO], HEX);
Serial.println( frame[FO+1], HEX);
Serial.println( frame[FO+2], HEX);
Serial.println( frame[FO+3], HEX);
*/

/*
18:50:29.213 -> 0
18:50:29.213 -> 0
18:50:29.213 -> 0
18:50:29.213 -> 0
*/
  //*******************  Frame 6  *******************
  FO=FrameOffset+FrameLength*5;
  Septet=Buffer[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);

  HeatQuantity=(frame[FO+1] << 8 | frame[FO])+(frame[FO+3] << 8| frame[FO+2])*1000;

Serial.println( F("Frame 6"));
Serial.println( frame[FO+1], HEX);
Serial.println( frame[FO+2], HEX);
Serial.println( frame[FO+3], HEX);

/*
18:50:29.213 -> D5
18:50:29.213 -> 0
18:50:29.213 -> 6
18:50:29.213 -> 1
*/

  //*******************  Frame 7  *******************
  FO=FrameOffset+FrameLength*6;
  Septet=Buffer[FO+FrameSeptet];
  InjectSeptet(frame,FO,4);

  HeatQuantity=HeatQuantity+(frame[FO+1] << 8 | frame[FO])*1000000;
  Scheme    =  frame[FO+2];

Serial.println( F("Frame 7"));
Serial.println( frame[FO], HEX);
Serial.println( frame[FO+1], HEX);
Serial.println( frame[FO+2], HEX);

/*
 * 32'390,643
afficher 32 390 KWH
18:50:29.213 -> 20
18:50:29.213 -> 0
18:50:29.213 -> 3
*/
}

// The following is needed for decoding the data
void  InjectSeptet(unsigned char *Buffer, int Offset, int Length) {
  for (unsigned int i = 0; i < Length; i++) {
    if (Septet & (1 << i)) {
      Buffer [Offset + i] |= 0x80;
    }
  }
}
 
// This function converts 2 data bytes to a temperature value.
float CalcTemp(int Byte1, int Byte2) {
  int v;
  v = Byte1 << 8 | Byte2; //bit shift 8 to left, bitwise OR
 
  if (Byte1 == 0x00){
    v= v & 0xFF; 
  }
 
  if (Byte1 == 0xFF)
    v = v - 0x10000;
 
  if (v==SENSORNOTCONNECTED)
    v=0;
 
  return (float)((float) v * 0.1);
}   

Entering inside the readVbusValue, and passing inside the if (!quit) crash.
I think of a buffer overflow, but can't find it anywhere
I try many Serial.print to catch the point where t crash, but can't find it, since it's when I call the sendData of this wifi part.

// wifi setting
int status = WL_IDLE_STATUS;
#define SERVER   "192.168.1.16"     // Host to contact
#define PORT     80                     // 80 = HTTP default port
#define NODE    "Solar"

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void initWifi(){
    // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println(F("Communication with WiFi module failed!"));
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println(F("Please upgrade the firmware"));
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print(F("Attempting to connect to SSID: "));
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 5 seconds for connection:
    delay(5000);
  }
  Serial.println(F("Connected to WiFi"));
  setColor( 0,0,255); // red until wifi is OK  

  printWifiStatus();
  setColor( 0,255,0); // red until wifi is OK  
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print(F("SSID: "));
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print(F("IP Address: "));
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print(F("signal strength (RSSI):"));
  Serial.print(rssi);
  Serial.println(" dBm");
}

void sendData(){
  Serial.println(F("\nStarting connection to server..."));
  if ( WiFi.status() != WL_CONNECTED ) {
    setColor( 255,0,0); // red until wifi is OK  
    Serial.println(WiFi.status());
    initWifi();
  }
  // if you get a connection, report back via serial:
  if (client.connected()) {
      Serial.println(F("Client connected to server"));
  }
  
  if (client.connect(SERVER, PORT)) {
      Serial.println(F("connected to server"));
    

    // Make a HTTP request:
    String HTTP_RQS = "GET /input/post?";
    HTTP_RQS += "node=";
    HTTP_RQS += NODE;
    HTTP_RQS += "&json={";
    HTTP_RQS += "ecs_high:";
    HTTP_RQS += ecs_high_temp;
    HTTP_RQS += ",ecs_low:";
    HTTP_RQS += ecs_low_temp;
    HTTP_RQS += ",solar_temp:";
    HTTP_RQS += solar_temp;
    HTTP_RQS += ",solar_ret:";
    HTTP_RQS += solar_ret_temp;
    HTTP_RQS += ",HeatQuantity:";
    HTTP_RQS += HeatQuantity/1000;
    HTTP_RQS += ",PumpSpeed:";
    HTTP_RQS += PumpSpeed1;
    HTTP_RQS += ",Relay:";
    HTTP_RQS += Relay;
    HTTP_RQS += ",ecs_in:";
    HTTP_RQS += ecs_in_temp;
    HTTP_RQS += ",pac_top:";
    HTTP_RQS += pac_top_temp;
    HTTP_RQS += ",pac_out:";
    HTTP_RQS += pac_out_temp;
    HTTP_RQS += ",pompeStatus:";
    HTTP_RQS += pompeStatus;
    HTTP_RQS += "}";
    HTTP_RQS += "&apikey=29ceaa8fdad3f5268a2c1f7fd730ce2c";
    HTTP_RQS += " HTTP/1.1\r\n";
    HTTP_RQS += "Host:192.168.1.16";
    HTTP_RQS += "\r\n\r\n";

// I try this part due to some report of error sending a String class, I try to send a char[]
    int str_len = HTTP_RQS.length()+1;
    char HTTP_QRY[str_len];
    HTTP_RQS.toCharArray( HTTP_QRY, str_len);

    client.println(HTTP_QRY);
 
    Serial.println(HTTP_QRY);

    delay(2000);
    while (client.available()) {
      char c = client.read();
      Serial.write(c);
    }
    client.stop();
  }
}

// set the RGB led
void setColor( uint8_t red, uint8_t green, uint8_t blue ) {

  WiFiDrv::analogWrite(25, green/20); // GREEN
  WiFiDrv::analogWrite(26, red/20); // RED
  WiFiDrv::analogWrite(27, blue/20); // BLUE  
}

Its great you found the issue :slight_smile:

If you don't have a multimeter I suggest you purchase one. You can find multimeters on Amazon for $15 to $30. You don't need a supper good one, mostly you need to measure voltages and sometimes resistance.

I always check voltages when working with a connector or component I'm not familiar with.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.