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
1 Answer 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.
-
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– Daan Mouha2015年09月14日 20:41:55 +00:00Commented 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 ...".2015年09月14日 20:50:47 +00:00Commented Sep 14, 2015 at 20:50
-
1Editted the question.Daan Mouha– Daan Mouha2015年09月15日 08:36:37 +00:00Commented Sep 15, 2015 at 8:36
Setup()