Go Down

Topic: max3232 not reading softwareserial input (Read 8837 times) previous topic - next topic

Akubra

Sep 13, 2014, 12:10 pm Last Edit: Sep 15, 2014, 02:26 am by Akubra Reason: 1
I have attached a maxr3232 board to my Uno, hooked it up as follows:
Uno RX pin (0) - max3232 TX
Uno TX pin (1) - max3232 RX
Gnd/3.3v

After some initial issues getting it to detect the board, .available() now returns true but the arduino doesn't seem to read any serial data from the max3232.

I'm using the following script to test:

Code: [Select]
#include <SoftwareSerial.h>
#define rxPin 0 // 10
#define txPin 1 // 11

int baudrate = 9600;
String command = ""; // Stores response of bluetooth device

SoftwareSerial softSerial(rxPin, txPin); // RX, TX

void setup()
{
 softSerial.begin(baudrate);

 Serial.begin(baudrate);
 Serial.println("HW Serial Ready!");
}


void loop() // run over and over
{
 if (softSerial.available()) {
   Serial.println("Soft Serial available");
 }
 else {
   Serial.println("Soft Serial not available");
 }

 int data = softSerial.read();
 Serial.println(data);
 Serial.println(char(data));

 delay(1000);
}


The arduino+maxrs232 are hooked up to a laptop running the arduino ise with the above script and the serial monitor.
I'm using a pc with usb/rs232 cable to send data to the arduino but nothing seems to be coming through.


This is the max3232 boatrd I'm using:
3.3V/5V MAX3232 Chip Female RS232 Serial to TTL Converter Module
http://www.ebay.com.au/itm/111228758957?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

Specification:
Product Name    RS232 Serial to TTL Converter Module
Chip    MAX3232
Working Voltage    3.3V/5V
Total Size    45 x 32 x 14mm/1.8" x 1.3" x 0.55"(L*W*H)
Package Content    

1 x RS232 Serial to TTL Converter Module

Description:

   Built-in MAX3232 or equivalent Transfer chip.
   Fully compatible with existing legacy COM port software.
   Easy to use, Compact design.
   Output signals: VDD TXD  RXD  CTS  RTS  GND.
   Power  TX RX LED.

Thnx

robtillaart


Please modify your post (Upper right of the post) , select the code part and press the # button (above the smileys)
That will insert code tags and makes the code better readable.

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart


Your sketch has a flaw.
Even when there is no data available you try to read from it

try this
Code: (not tested) [Select]

#include <SoftwareSerial.h>
#define rxPin 0 // 10
#define txPin 1 // 11

int baudrate = 9600;
String command = ""; // Stores response of bluetooth device

unsigned long nr = 0;

SoftwareSerial softSerial(rxPin, txPin); // RX, TX

void setup()
{
  softSerial.begin(baudrate);

  Serial.begin(baudrate);
  Serial.println("HW Serial Ready!");
}


void loop() // run over and over
{
  if (softSerial.available())
{
    Serial.println("Soft Serial available");

    char data = softSerial.read();
    Serial.print(nr);  // which byte
    nr++;
    Serial.print("\t");
    Serial.print(data);  // integer format
    Serial.print("\t");
    Serial.println(char(data));   // ascii format
  }
}

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Quote
After some initial issues getting it to detect the board, .available() now returns true

No, it does not. Go read the documentation for available() to see what it DOES return,

Robin2

Why have you two Threads about the same subject. Double posting just wastes everyone's time.

You have not answered the question I asked in the other Thread about what is on the other side of the Max3232.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Akubra

@Paul: sorry about that. Would like to continue the conversation in this thread.
As a test and learning thing I' m trying to send data from my pc to the Arduino over rs232.
When I know that works (and more importantly 'how') I want to read data from other devices with a comm port.

@robtillaart: post updated with code tag. Will try your update tonight when I get home.



max_saeta

#6
Sep 15, 2014, 03:07 am Last Edit: Sep 15, 2014, 03:09 am by max_saeta Reason: 1
Saludos.

Respondo en espaƱol porque mi ingles apesta. El problema que tienes es conficto de hardware.
Esta usando los pines 0 y 1 para SoftwareSerial, y al mismo tiempo usas la comunicacion por hardware.

Cambia la coneccion de los pines 0 y 1 a 2 y 3, ademas tu sketch debe ser:
-------------------------------------------
Greetings.

I answer in Spanish because my English sucks. The problem you have is hardware confict.
This using pins 0 and 1 for SoftwareSerial, while using the communication hardware.

Change the connection pins 0 and 1 to 2 and 3, plus your sketch should be:
Code: [Select]

#include <SoftwareSerial.h>
#define rxPin 2 // 10
#define txPin 3 // 11

int baudrate = 9600;
String command = ""; // Stores response of bluetooth device

unsigned long nr = 0;

SoftwareSerial softSerial(rxPin, txPin); // RX, TX

void setup()
{
 softSerial.begin(baudrate);

 Serial.begin(baudrate);
 Serial.println("HW Serial Ready!");
}


void loop() // run over and over
{
 if (softSerial.available())
{
   Serial.println("Soft Serial available");

   char data = softSerial.read();
   Serial.print(nr);  // which byte
   nr++;
   Serial.print("\t");
   Serial.print(data);  // integer format
   Serial.print("\t");
   Serial.println(char(data));   // ascii format
 }
}


Akubra

Switched RX=0 and TX=1 to RX=10 and TX=11.
0 and 1 seem to be used by the onboard serial. If I use those pins the RX light on the MAX3232 lights up at the same time as the RX light on the Arduino Uno (which is still connected to the laptop via USB to watch the serial monitor).

After the change to RX/10 and TX/11 or (8/9) nothing seems to happen, softSerial.available() never seems to become true.
I have connected a USB/RS232 cable to the Arduino Uno/MAX3232 and the other end into a PC (com 5).
When I send some text using a command line serial send util to com5 it says "written" on the pc side but the RX light on the MAX3232 never lights up.

max_saeta

Hi,
You have to switch  RX=0 and TX=1 to RX=2 and TX=3.

Robin2

As @max_saeta says you must match the pins you use to the values for Rx and Tx in the code.

Do you have any other device that could send TTL serial data to softwareSerial - the code looks like it should work.

If you use pin 13 as the Rx pin I think the onboard LED should flash to give you an indication that data is being received.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Akubra

@max_saeta: I did match the code to use the correct pin combination.

@Robin2: haven't tried pin 13.

At the moment I don't have any other device which can send data to the Arduino + MAX3232 other then my pc with a usb/serial cable.

max_saeta

Well, there's a condition to use Software Serial, RX has to be connect to a pin with interrupt.

Akubra

#12
Sep 16, 2014, 03:52 am Last Edit: Sep 16, 2014, 12:49 pm by Akubra Reason: 1
Ok, made some progress with RX on pin 2 and and TX on 3. Running TeraTerm on the computer connected via the RS232 cable, I can see text send from the Arduino (still connected to the laptop via usb) coming in.
Now the only thing I need to get working is the other way around. Send text from the computer to the Arduino using Software serial.

Thanks all for help so far.


Go Up