Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rs232 problem
#11
(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
Reply
#12
sorry, these days very busy. after finished it, i will upload to here.
Reply
#13
I have used this code
// Imposta i GPIO a cui sono connessi TX e RX del chip SP3232EEN
#define RXD2 16  // Pin RX
#define TXD2 17  // Pin TX

void setup() {
  // Inizializza la porta seriale principale per il debug a 115200 baud
  Serial.begin(115200);
  // Inizializza la seconda porta seriale (Serial2) per comunicare con il chip SP3232EEN
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);  // 9600 baud per esempio

  // Messaggio di avvio
  Serial.println("Test della comunicazione con il chip SP3232EEN tramite GPIO 16 e 17.");
}

void loop() {
  // Controlla se ci sono dati disponibili da Serial2
  if (Serial2.available()) {
    // Legge i dati ricevuti da Serial2
    String dataFromSP3232 = Serial2.readString();
    // Stampa i dati ricevuti sulla Serial per il monitoraggio
    Serial.print("Dato ricevuto dal chip SP3232EEN: ");
    Serial.println(dataFromSP3232);
  }

  // Se ci sono dati disponibili sulla Serial (ad esempio dal monitor seriale dell'IDE Arduino)
  if (Serial.available()) {
    // Leggi il dato dalla Serial
    String dataToSend = Serial.readString();
    // Invia il dato a Serial2 (SP3232EEN)
    Serial2.print(dataToSend);
    Serial.print("Dato inviato al chip SP3232EEN: ");
    Serial.println(dataToSend);
  }
}

Tell me if is right.
The pin 16 and 17 works. The serial chip no
Reply
#14
(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
Reply
#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: 23)
Reply
#16
I don't receive any answer


Attached Files Image(s)
   
Reply
#17
can you weld U14 chip: SP3232EEN
Reply
#18
Do you mean remove it? Or what?
Reply
#19
can you weld it again, if also can't work, maybe need replace a new one.
Reply
#20
I don't understand what I have to do. I have to bridge tx and Rx?
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)