10-01-2024, 02:42 AM
(09-24-2024, 12:42 PM)admin Wrote: [ -> ]tomorrow when i have free time, write a test code for you.
Me puedes apoyar con el codigo de ejemplo del puerto rs232
gracias
(09-24-2024, 12:42 PM)admin Wrote: [ -> ]tomorrow when i have free time, write a test code for you.
(10-01-2024, 04:40 AM)GRACIAS alex989 Wrote: [ -> ]lo probare y comparto las pruebas, una pregunta si tengo el serial 2 direccionado al rs485 como le hago para usar el tercer puerto serie
// 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 = "";
}
}
}