Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rs232 problem
#15
use this arduino code to test RS232:
Code:
// Define GPIO pins for RS232 interface
#define RS232_TXD 17
#define RS232_RXD 16

unsigned long previousMillis = 0;  // To store the last time the message was sent
const long interval = 2000;        // Interval between messages (2 seconds)

String receivedData = "";  // Buffer to store received data

void setup() {
  // Initialize the serial port for debugging
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for the serial port to initialize
  }
 
  // Initialize the RS232 serial port
  Serial2.begin(9600, SERIAL_8N1, RS232_RXD, RS232_TXD);
 
  // Wait for the serial communication to stabilize
  delay(1000);
}

void loop() {
  // Get the current time
  unsigned long currentMillis = millis();
 
  // Check if 2 seconds have passed since the last message was sent
  if (currentMillis - previousMillis >= interval) {
    // Update the last time the message was sent
    previousMillis = currentMillis;

    // Send the test string
    Serial2.println("KinCony A6 RS232 Test!");

    // Print the sent message to the serial monitor
    Serial.println("Sent: KinCony A6 RS232 Test!");
  }

  // Check if there is data available from the RS232 serial port
  while (Serial2.available()) {
    char c = Serial2.read();
    // Append the received character to the buffer
    receivedData += c;
   
    // Check if the end character '!' is received
    if (c == '!') {
      // Print the complete received message
      Serial.print("Received: ");
      Serial.println(receivedData);

      // Clear the buffer to receive the next message
      receivedData = "";
    }
  }
}
   
short RXD,TXD of RS232 port.
   
You will send TEXT sent by RS232 and received, it will print by USB.
here is BIN file can directly to download at 0x0 address.

.zip   RS232-test.ino.merged.zip (Size: 171.07 KB / Downloads: 95)
Reply


Messages In This Thread
rs232 problem - by alex989 - 09-22-2024, 04:08 PM
RE: rs232 problem - by admin - 09-22-2024, 10:12 PM
RE: rs232 problem - by alex989 - 09-23-2024, 08:14 AM
RE: rs232 problem - by admin - 09-23-2024, 02:09 PM
RE: rs232 problem - by alex989 - 09-23-2024, 08:50 PM
RE: rs232 problem - by admin - 09-23-2024, 11:20 PM
RE: rs232 problem - by alex989 - 09-24-2024, 03:59 AM
RE: rs232 problem - by admin - 09-24-2024, 06:25 AM
RE: rs232 problem - by alex989 - 09-24-2024, 06:44 AM
RE: rs232 problem - by admin - 09-24-2024, 12:42 PM
RE: rs232 problem - by sistemasyusa - 10-01-2024, 02:42 AM
RE: rs232 problem - by admin - 10-01-2024, 02:44 AM
RE: rs232 problem - by alex989 - 10-01-2024, 04:40 AM
RE: rs232 problem - by sistemasyusa - 10-01-2024, 07:49 AM
RE: rs232 problem - by admin - 10-02-2024, 06:36 AM
RE: rs232 problem - by alex989 - 10-02-2024, 07:48 PM
RE: rs232 problem - by admin - 10-03-2024, 04:04 AM
RE: rs232 problem - by alex989 - 10-03-2024, 04:40 AM
RE: rs232 problem - by admin - 10-03-2024, 10:51 AM
RE: rs232 problem - by alex989 - 10-03-2024, 12:25 PM
RE: rs232 problem - by admin - 10-04-2024, 12:40 AM
RE: rs232 problem - by alex989 - 10-24-2024, 08:48 PM
RE: rs232 problem - by admin - 10-24-2024, 11:49 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)