0
\$\begingroup\$

I'm trying to connect Atmega328P to PC via RS232, the Microcontroller code is basically a : Serial.write("Greetings !"); inside the loop function. I've tried the following circuit but it doesn't work and doesn't show anything in my serial monitor : enter image description here

Am I missing anything here ??


Here is the full code:

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

void loop() {
  // put your main code here, to run repeatedly:
  Serial.write("Greetings !");
  Serial.write("\n");
  delay(1000);
}
\$\endgroup\$
  • 2
    \$\begingroup\$ Disconnect TXD and RXD from the MCU and link them together at the MAX232, then trying sending some characters in a terminal program. Do they echo back? \$\endgroup\$ – Bruce Abbott May 24 '17 at 7:54
  • \$\begingroup\$ Thanks for your comments guys ! @BruceAbbott I just tried your suggestion , unfortunately, they don't echo back. \$\endgroup\$ – Mark Ziplo May 24 '17 at 8:15
  • 1
    \$\begingroup\$ "unfortunately, they don't echo back' - Disconnect the MAX232 and link the serial port pins 2 and 3 together. If it still doesn't echo back then you have a cable fault or problem in the PC. If it works then the problem is with the MAX232 (incorrect wiring, reversed caps, lack of Vcc, bad chip?). Fix this first before looking at the MCU code! \$\endgroup\$ – Bruce Abbott May 24 '17 at 9:02
  • \$\begingroup\$ swap pins 2 and 3 on the rs-232 connector \$\endgroup\$ – charlie May 24 '17 at 20:35
1
\$\begingroup\$

Since your design includes two ICs, I suggest you debug them separately. Bruce already suggested a good test for the MAX232: connect TXD and RXD pins together and see if whatever you send from the PC echoes back.

A good test for the Atmega chip is to connect it to your PC via a USB UART and see if you can read your greetings message. If you don't have a USB UART, connect a LED to the TX pin:

schematic

simulate this circuit – Schematic created using CircuitLab

If you have programmed the MCU correctly, the LED should briefly blink every second, as MCU is transmitting your "Greetings" message.

Finally, since you don't show how you connect the two ICs, so you may want to double check that. Do they have a common ground? Did you connect TX to RX and vice versa?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.