I am working on transmitting temperature data from an E32 module to an E95-DTU. I attempted to send the data in a Modbus RTU structure using the following format:
01 04 02 09 A1 7E D8
However, when I attempt to receive the data, I get the following response:
FB 01 02 09 A1 7E D8
Could you please explain what the "FB" byte signifies? I did not include it in the data I sent. Additionally, I would appreciate guidance on preparing the correct format to ensure successful data transmission.
#include "LoRa_E32.h"
#include <SoftwareSerial.h>
int16_t temperature;
SoftwareSerial mySerial(3, 2);
LoRa_E32 e32(&mySerial);
uint16_t calculateCRC(uint8_t *buffer, uint8_t length) {
uint16_t crc = 0xFFFF;
for (uint8_t i = 0; i < length; i++) {
crc ^= buffer[i];
for (uint8_t j = 0; j < 8; j++) {
if (crc & 0x0001) {
crc >>= 1;
crc ^= 0xA001;
} else {
crc >>= 1;
}
}
}
return crc;
}
void setup() {
Serial.begin(9600);
e32.begin();
void loop() {
temperature = 2465;
uint8_t modbusPacket[8];
modbusPacket[0] = 0x01;
modbusPacket[1] = 0x04;
modbusPacket[2] = 0x02;
modbusPacket[3] = (temperature >> 8) & 0xFF;
modbusPacket[4] = temperature & 0xFF;
// CRC hesapla
uint16_t crc = calculateCRC(modbusPacket, 5);
modbusPacket[5] = crc & 0xFF;
modbusPacket[6] = (crc >> 8) & 0xFF;
e32.sendMessage(modbusPacket, sizeof(modbusPacket));
Serial.print("Sent Packet: ");
for (int i = 0; i < sizeof(modbusPacket); i++) {
Serial.print(modbusPacket[i], HEX);
Serial.print(" ");
}
Serial.println();
delay(1000);
}