Jump to content
43oh

communication between two UART on Tiva C


Recommended Posts

I want to resend each character from one UART port to another.

Hardware: Lauchpad TivaC EK-TM4C123GXL.

First port is the default port that is connected to microUSB on the board.

The second port is UART2 (Rx = PD6; Tx = PD7) connected to DB9 through MAX3232:. Power is VBUS - GND.

DB9 is now connected to computer through RS232-USB adapter.

I communicate with 1st serial port through serial monitor in Energia (ttyACM0).

I communicate with 2nd serial port through serial terminal in Linux (ttyUSB0). 

Code is very simple:

void setup() {
  // initialize ports:
  Serial.begin(9600); //connected with USB
  delay(100);
  Serial2.begin(9600); //RS232: Rx = PD6; Tx = PD7
  delay(100);
}

void loop() {
}

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    //send it to RS232
    Serial2.print(inChar); 
  }
  while (Serial2.available()) {
    // get the new byte:
    char inChar = (char)Serial2.read();
    //send it to UI
    Serial.print(inChar); 
  } 
}

I got the following:

Then I send something from Energia serial monitor (serial) - this message is displayed in linux serial terminal (serial2) - this is all good.

Another way (from Serial2 to Serial) it does not work - I send messages from linux terminal, but nothing changes in Energia serial monitor.

 

What is wrong with my setup?

Link to post
Share on other sites

The Sketch looks good. As a sanity check, can you connect PD6/PD7 and run the Sketch below?

This should continuously print H to the Serial Monitor.

 

If that works, the check the connections to the MAX3232 and make sure that the Rx pin of the LaunchPad is connected to the Tx pin of the MAX3232.

void setup()
{
  // put your setup code here, to run once:
  Serial2.begin(9600);
  Serial.begin(9600);
}

void loop()
{
  // put your main code here, to run repeatedly:
  Serial2.print("H");
  char inChar = (char)Serial2.read();
  Serial.print(inChar);
  delay(200);
} 

Robert

Link to post
Share on other sites

Another suggestion is to test a Windows PC instead of the Linux machine to determine if it is contributing to the problem. Also, if you have a logic analyzer (e.g. Saleae) that would let you see what the transmissions actually look like. If you don't have one, and you think you will do even a modest amount of microcontroller communications work, a good logic analyzer is worth its weight in gold.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...