10-02-2024, 06:36 AM
use this arduino code to test RS232:
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.
RS232-test.ino.merged.zip (Size: 171.07 KB / Downloads: 86)
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.
