One wire serial issues

Hi, I'm working on communicating with my Pellet oven, that uses a one wire serial. I have made a converter that has worked before, so I suspect my code for the ESP32s

The oven works by me (ESP32) sending two bytes 0x00 for RAM and then 0x03 for RAM adr with water temp.
I then get two bytes back, CRC and the Temp.

The issue is that I'm supposed to get CRC 47 and Temp 44 back (CRC is 3+temp 44 = 47)

First time I get 0 & 3, Next time I get 47 & 44 and this way it continues.
Looks like I'm getting a empty byte first or ?

int  askretur1;
int  askretur2;
//Oven messages
byte messageon  [] = {0x80, 0x21, 0x01, 0xA2};
byte messageoff [] = {0x80, 0x21, 0x06, 0xA7};
byte messageask [] = {0x00, 0x03};

void setup() {
  Serial2.begin (1200, SERIAL_8N2);
  Serial.begin(115200);



            
  
void loop(){                    
              Serial2.write (messageask, sizeof (messageask));    //Sending {0x00, 0x03} to ask for Temp, 
              if (Serial2.available() >= 2) {                     //If both bytes recieved 
                delay(100);
                askretur1=Serial2.read();                         //Get first byte (expected CRC)
                delay(100);
                askretur2=Serial2.read();   }                     //Get second byte (expect Temp value)
                              
              Serial.println(" Byte1: ");                         //Send to serial monitor
              Serial.write(askretur1);
              Serial.println("  Byte2: ");
              Serial.write(askretur2); 
              delay(5000);

}

Thanks for any help.

I guess you have connected Serial2's RX and TX to create the single wire serial interface.

In which case the two bytes that you send are received first. It will probably work correctly if you check if four bytes are available instead of two.

Of course, so simple, thanks, made my day..

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