papa 0 Posted March 11, 2016 Share Posted March 11, 2016 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? Quote Link to post Share on other sites
energia 485 Posted March 11, 2016 Share Posted March 11, 2016 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 Quote Link to post Share on other sites
papa 0 Posted March 12, 2016 Author Share Posted March 12, 2016 Running your code I got the following: On Serial ttyACM0: Quote Link to post Share on other sites
dubnet 238 Posted March 12, 2016 Share Posted March 12, 2016 My 2 cents....try adding a 300-500ms delay before you start your loop. I have found that to solve a similar problem I was having, YMMV. Quote Link to post Share on other sites
papa 0 Posted March 12, 2016 Author Share Posted March 12, 2016 My 2 cents....try adding a 300-500ms delay before you start your loop. I have found that to solve a similar problem I was having, YMMV. Tried - same abra-cadabra Quote Link to post Share on other sites
dubnet 238 Posted March 13, 2016 Share Posted March 13, 2016 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. spirilis 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.