Good afternoon people.
I'm developing a communication project using MODBUS.
Equipment/Software:
Mini Arduino
USB/RS232 TTL FTDI module
I2C LCD Display
PC Win10
Radzio!ModBus Master Software
During the project I encountered a situation that I couldn't understand.
To make it easier, I built a very small sketch to test the problem.
To test MODBUS I use the small Radzio!ModBus Master software.
Modbus Master Simulator - free software utility for testing Modbus slave devices
To use this soft just configure the serial and then click Open.
On the screen select "Lenght 8" and click on Connect.
As the sketcht does not send anything to the master, the ModBus message timeout msg will appear on the soft screen.
This soft sends values ββas shown on the screen to the arduino, by serial each time
of the logic analyzer.
The soft also generates a log named " Transmission.log ", with the data that was sent,
in the folder where it was installed.
In this folder I have the values ββsent by the soft equal to
"0x01 0x01 0x00 0x00 0x00 0x08 0x3D 0xCC".
With my sketch, I get these bytes, saved in an array and when the serial is empty,
I print these values ββin Hexadecimal on an LCD.
The LCD should show the values ββ"1100083DCC", but it shows the values ββ"0083DFFFFFFCC110".
I couldn't understand the reason for this problem.
Thanks in advance.
Regards
RV mineirin.
#include <LiquidCrystal_I2C.h> // Lib LCD I2C
LiquidCrystal_I2C lcd(0x39, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
byte i = 0; // Count control
char received[8] ; // Array to save data from serial
bool rec = false; // Flux Control
//-------------------------------------------------------------------------------------
void setup()
{
Serial.begin(9600); // Inicialise Serial
lcd.begin(2, 16); // Inicialise LCD
lcd.clear(); // Clear LCD
}
//-------------------------------------------------------------------------------------
void loop()
{
while (Serial.available() > 0) // While data on Serialo
{
received[i] = Serial.read(); // Read data on array
i++; // Increment count
rec = true; // Sinalise data on array
}
if (rec == true) // If data on array
{
for ( int j = 0; j < 8; j++) // Selecta 0 to 8 array cell
{
lcd.print(received[j], HEX); // LCD display in HEX
}
rec = false; // Sinalise no data on array
lcd.setCursor(0, 0); // Select pos 0 line 0 LCD
}
}
Read on the RX pin of the arduino.

