0

I didn't find answers which solves my problem with the max232 yet. I connected it like this to my Arduino uno, so my Arduino provides the +5V VCC and the ground: max232 connection Connection on board

The only thing what is differences are that I do a loopback at the RS232 side and I use 1µF for every capacitor even for the bypass one. I did a loopback so I can see if the max232 works. I don't get anything out of it when I send some data to it. I measure +8.7V on pin2 and -8.15V on pin 6.

My Arduino code:

/*
  Software serial multiple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit: 
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.print(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

What did I do wrong or is my max232 broken?

EDIT

I think the serial monitor (same baudrate) doesn't write to the ports so I rewrite some code.

loop code:

int i = 0;
void loop() // run over and over
{
  if(i == 10)
    i = 0;

  mySerial.write(i);
  Serial.print(mySerial.read());
  i++;
  delay(3000);
}

In serial monitor I get strange values back for a cascade counter.

Values: -1 45 49 52 53 52 57 53 ...

These numbers aren't ascii code for ectual numbers I think.

EDIT 2

Now the loopback works thanks to the answer below. Now I replaced the loopback with the module FUM DCF-U. The loop code has changed to this:

void loop() // run over and over
{
  if(Serial.available())
    Serial.println(Serial.read());
}

The problem is that the result is '000000000000000000000000000000000...' in a fast rate and not every second.

The module gets its 3.3V and is connected to the same GND as the MAX232.

Pin connections:

Arduino - MAX232

11 - 11

0 - 12

MAX232 - FUM DCF-U

14 - 3

13 - 4

Thanks in advance

14
  • 1
    Does loop back work without the MAX232? Commented Sep 2, 2015 at 15:36
  • 1
    Tried the loopback without the MAX232 and it doesn't work, even when I use the 0 and 1 pins. What is wrong with my arduino?
    – Daan Mouha
    Commented Sep 2, 2015 at 16:03
  • 1
    Yes. I rewrite my code see EDIT in main question, I still get some strange input.
    – Daan Mouha
    Commented Sep 2, 2015 at 17:52
  • 1
    I get the "hello world!" in my monitor in Setup()
    – Daan Mouha
    Commented Sep 2, 2015 at 18:00
  • 1
    It's just a cascade counter like my edited code shows. These numbers is the result of the loopback which I find very strange. Especially with in mind that this is a test run to see if everything is working before I add it to an atomic clock receiver.
    – Daan Mouha
    Commented Sep 2, 2015 at 18:07

1 Answer 1

1

SoftwareSerial cannot both send and receive at the same time, as it does receiving inside an ISR, and turns interrupts off when sending. Thus this will never work properly.

I suggest you switch to HardwareSerial. Or, if you want to see the results, send using SoftwareSerial and receive using HardwareSerial. For example:

#include <SoftwareSerial.h>
SoftwareSerial mySerial (10, 11); // RX, TX

void setup ()
  {
  Serial.begin (115200);
  mySerial.begin (115200);
  }  // end of setup

unsigned long lastSend;
char c = ' ';
void loop ()
  {
  // time for another test send?
  if (millis () - lastSend >= 500)
    {
    mySerial.print (c++);
    if (c > 'z')
      {
      c = ' ';
      Serial.println ();
      }    
    lastSend = millis ();
    }

  // check for response
  if (Serial.available ())
    Serial.print (char (Serial.read ()));
  }  // end of loop

I tested that as a simple loopback and it worked fine. Connect pin 11 (Tx) to pin 0 (Rx). Disconnect the wire to pin 0 whilst uploading.

3
  • My loopback works fine but now I added my atomic clock module the FUM DCF-U and changed the code so that only the last if-clause remains. This results in only '0' (without the char cast) in a fast rate instead of some data every second. Why does this happen?
    – Daan Mouha
    Commented Sep 14, 2015 at 20:41
  • Perhaps amend your question, and post this amended code. Neither my colleagues here, nor I, are good at debugging code where "I changed a few things but ...".
    – Nick Gammon
    Commented Sep 14, 2015 at 20:50
  • 1
    Editted the question.
    – Daan Mouha
    Commented Sep 15, 2015 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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