Hi !
I have the following configuration:
Atmega328pb with MAX485 module, on the other side a usb RS485 adapter (on pc)
When I send data via the arduino or via the PC I receive anything, example:
Arduino send '1'
PC receive: 00 67 00
PC sending 0x01
Arduino get 67
Except that the 67 does not correspond to anything (ASCII HEX DEC)
void setup() {
delay(1000);
delay(1000);
delay(1000);
// initialize serial:
Serial.begin(9600);
Serial1.begin(9600);
pinMode(10, OUTPUT);
}
void loop() {
const int BUFFER_SIZE = 50;
char buf[BUFFER_SIZE];
while (Serial1.available() > 0) {
// read the incoming bytes:
int rlen = Serial1.readBytes(buf, BUFFER_SIZE);
Serial.print( rlen );
Serial.print( " --- " );
// prints the received data
for(int i = 0; i < rlen; i++)
Serial.print(buf[i], HEX);
}
if(Serial.available() > 0) {
byte ch = Serial.read();
if (ch != '\n') {
Serial.print( " --- char : " );
Serial.println( ch, HEX );
digitalWrite(10, HIGH); // Transmit
delay(100);
Serial1.write( ch );
delay(100);
digitalWrite(10, LOW); // Receive
}
}
delay(100);
}