Baud rate conversion

I'm new to this, so thank you for your patience!
I'm trying to make an old system talk to a new vacuum controller called an MKS. I have the manuals for the 2 MKS systems but no Manual or any details on the Utility card it connects to. the programming language is in the manuals and seems to be the same. the utility card baud rate is 4800 and the new MKS lowest is 9600. Both are 8 data bits, 1 stop bit, No parity, No hardware handshaking for the two MKS systems. I would upload the Manuals but it won't let me due to new user.

example of the communication should be like this
@0651:1E-10

but this is what i get
03:56:18.468 -> FFFFFFFF
03:56:18.468 -> FFFFFFFF
03:56:18.501 -> FFFFFFFF
or
03:43:26.294 -> -1
03:43:26.294 -> 255
03:43:26.294 -> 255
03:43:26.294 -> 255
03:43:26.294 -> 0
03:43:26.294 -> -1

#include <SoftwareSerial.h>

#define SERIAL_8N1 0x06

void setup() {

  // Configure Serial1 to receive at a higher baud rate (e.g., 9600)
  Serial1.begin(9600, SERIAL_8N1);

  // Configure Serial2 to transmit at a lower baud rate (e.g., 4800)
  Serial2.begin(4800, SERIAL_8N1);

  // Optionally, you can print a message to the serial monitor
  Serial.begin(9600, SERIAL_8N1);  // Use Serial for debugging
  Serial.println("Baud Rate Converter Started");
}

void loop() {

  // read from port 1, send to port 0:

  while (Serial1.available()) {

    Serial2.write(Serial1.read());
    Serial.println(Serial1.read());
  }

  // read from port 0, send to port 1:

  while (Serial2.available()) {

    Serial1.write(Serial2.read());
    Serial.println(Serial2.read());
  }
}

thanks again for your patience

Read/scroll 10 posts on 10 topics over 10 minutes and you will be granted file posting privs.

Which Arduino are you using?

Why are you including SoftwareSerial when you are not using it?

< edit >

  while (Serial1.available()) {
    Serial2.write(Serial1.read());
    Serial.println(Serial1.read());
  }

You are reading two bytes when there may only be one available, and you are sending only every other byte to each port. Use Serial1.peek() instead of the first Serial1.read().

(sorry, a bit slow this morning, will get it edited correctly eventually)

1 Like

Noticed another problem. read() returns an int, so the println() will print the numeric value of the character, not the ASCII character itself. Unless that is what you want, you need to either cast the read() to char, or use write() instead of println(), in which case you would need to send the carriage return and linefeed afterwards.

@sirnoobian
No, like this:

  while (Serial1.available()) {
    char c = Serial1.read();
    Serial2.write(c);
    Serial.println(c);
  }
2 Likes

Check that again. It should be 1 start bit, 8 data bits, 1 stop bit.

Chars per second should be baud rate /10. This is Arduino default, btw.

 read() returns an int,

If you read into a char variable as PaulRB shows, you get the low 8 bits of that int return which is right/exactly what you want.

Be careful! They offer both RS-232 and RS-485 communications options. Neither will work with your Arduino without a conversion adapter. Which communications option does your controller have?

1 Like

Isn't that due to voltages? IIRC (probably wrong) RS232 is +6V HIGH and either -6V or GND LOW.

Could be true. The RS-232 standard called for +3 to +25 volts and -3 to -25 volts. The revised standard, RS-232C reduced the high values to +12 and -12. The original was for vacuum tubes(valves). The revised for transistors. The alternation between + and - came from teletype systems which used the same system as the telegram system that used Morse code! The basic reason was the need for distance between stations.

1 Like

Yes, but also the logic level is inverted. You can use RS-232 voltages, usually, with nothing but a current limit resistor on the input side, but your code needs to use the opposite high/low.

Some software serial allows you to say, there are microprocessors where you can do the inversion with an i/o control bit.

a7

The smart thing seems to be use a Max232 chip!
I have a bunch somewhere from Terry King's Yourduino shop.

Good to know. I will correct this and upload the files. thank you

So it needs to be like this? without the Software serial?


void loop() {

  // read from port 1, send to port 0:

  while (Serial1.available()) {
    char c = Serial1.read();
    Serial2.write(c);
    Serial.println(c);
  }

  // read from port 0, send to port 1:

  while (Serial2.available()) {
    char c = Serial2.read();
    Serial1.write(c);
    Serial.println(c);
  }
1 Like

The MCU that it is plugged into requires RS232 baud rate 4800, 8n1.

MKS 946.pdf (1.8 MB)
MKS146C.pdf (1.4 MB)

Arduino Mega 2560

Serial – RS-232 and RS-485; 9600, 19200, 38400, 57600,115200

the Series 946 manual says the baud rate is selectable

Yes, it is selectable, but the minimum speed is 9600 baud.

The problem is that the device that needs to communicate with the MKS 946 is working at 4800 baud, (with no currently known way of changing it).

A parameter is a value or option you add or alter when you give a command or execute a function. The result is that the command or function accomplishes its task in the way that you want. If you do not enter a parameter, the 146 unit operates according to default values. For example, the default baud rate for RS-232 communications is 9600.

what kind of conversion adapter would i need?