Hi,
I’ve been struggling with a strange problem for several days now. I have a soil moisture sensor that sends data through a modbus (RS485 <> TTL) interface. I use a HTCC-AB02s because it has a second serial port. The process is simple, I send a request and get the data from some registers. But whatever I try I only get 7 bytes of data back while I see on my logic analyzer that 11 bytes are received. Does anyone have any suggestions?
static void prepareTxFrame( uint8_t port )
{
digitalWrite(GPIO7 , HIGH); // Power up the modbus interface and sensor
delay(500);
//Send request to modbus sensor
uint8_t request[] ={0x01,0x03,0x00,0x00,0x00,0x03,0x05,0xCB} ; // Sensor request (first 3 registers)
for (int n=0; n<8 ; n++)
{
Serial1.print(char(request[n]));
}
delay(300);
//recieve data from modbus sensor
uint8_t serialBuffer[11] = {0} ;
int i=0;
while (Serial1.available())
{
serialBuffer[i] = (char) Serial1.read();
i++;
}
Serial.println(i-1);
appDataSize = 6;
appData[0] = serialBuffer[3]; //Temp msb
appData[1] = serialBuffer[4]; //Temp lsb
appData[2] = serialBuffer[5]; // moister msb
appData[3] = serialBuffer[6]; // moister lsb
appData[4] = serialBuffer[7]; // EC msb
appData[5] = serialBuffer[8]; // EC lsb
digitalWrite(GPIO7, LOW); // Power down the modbus interface and sensor
}