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

Daan Mouha
  • 109
  • 4
  • Could you use an oscilloscope and look at both TX lines? –  Sep 02 '15 at 15:09
  • I don't have an oscilloscope ;) –  Sep 02 '15 at 15:10
  • 1
    Does loop back work without the MAX232? – Spehro Pefhany Sep 02 '15 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? –  Sep 02 '15 at 16:03
  • I've never used the Arduino/sketches but I don't see in your code where you have actually written anything to the port. Is that all of the code? You're checking if anything is available but there won't be until you've given it something to start with. Your `if` statements could be returning false each time in the loop and so you never `write` anything or `print` anything. –  Sep 02 '15 at 17:33
  • I use the serial monitor to check which data is coming in. With this monitor I can send some data but can it be that it doesn't write to the ports what I thought it did? –  Sep 02 '15 at 17:38
  • Okay, and the baud rate that you are using in the serial monitor matches (9600)? –  Sep 02 '15 at 17:51
  • 1
    Yes. I rewrite my code see EDIT in main question, I still get some strange input. –  Sep 02 '15 at 17:52
  • In `setup()` have you tried to write something to the monitor, e.g. `Serial.println("Hello world");`? Just to see if it's working correctly. –  Sep 02 '15 at 17:55
  • 1
    I get the "hello world!" in my monitor in `Setup()` –  Sep 02 '15 at 18:00
  • Tried it again and now it is: 89 13 92 35 11 18 61 89 ... –  Sep 02 '15 at 18:02
  • Well, it appears that the wiring/hardware is working anyway. Not sure what you're doing to get those numbers. See http://www.asciitable.com/. –  Sep 02 '15 at 18:05
  • 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. –  Sep 02 '15 at 18:07
  • 1
    Now I tried to just send 'a' instead of an integer. The returned values are: 89 139 235 11 186 189 ... I changed to other ports and now I get -1 -1 -1 -1 -1 ... –  Sep 02 '15 at 18:13

1 Answers1

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.

Nick Gammon
  • 35,792
  • 12
  • 63
  • 121
  • 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 Sep 14 '15 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 Sep 14 '15 at 20:50
  • 1
    Editted the question. – Daan Mouha Sep 15 '15 at 08:36