Go Down

Topic: Max232 problem (Read 789 times) previous topic - next topic

binooetomo

Dear All

I build RS232 level shifter using max232, and use it wih NewSoftSerial at pin 4,5
My arduino is Arduino 2009

And here is my test script
Code: [Select]

#include <NewSoftSerial.h>  //Include library newsoftserial
#include <string.h>
char incoming_char=0;      //incoming char
char incoming_char_buff[300] ; //Incoming char buffer
int  incoming_char_idx = -1 ;  // Incoming char index
NewSoftSerial cell(4,5);
bool isprintline = 1;

void setup(){
  Serial.begin(19200);
  cell.begin(4800);
  delay(2000);
  Serial.println("Get Ready");
  delay(2000);
}
long myint = 0 ;
void loop(){
  /*
  cell.print("This is line number : ");
  cell.println(myint);
  Serial.print("This is line number : ");
  Serial.println(myint);
  myint++;
  delay(1000);
  */
  myint++;
  Serial.print("Loop Number : ");
  cell.print("Loop Number : ");
  Serial.println(myint);
  cell.println(myint);
 
  Serial.println("Let's check all lines");
  Serial.println("Check Cell Line");
  if(cell.available() >0){
    do_cell();
  }
  Serial.println("Check Serial Line");
  if(Serial.available() >0){
    do_ser();
  }
  delay(1000);
  if (isprintline){
    Serial.print("-----NO Thing Happen----------");
    cell.print("-----NO Thing Happen----------");
  }
  isprintline = 1 ;
}

void do_cell(){
  Serial.println("Reading Cell line");
  delay(100);
  incoming_char_idx=-1;
  while (cell.available()){
    incoming_char_idx++ ;
    incoming_char=cell.read();
    incoming_char_buff[incoming_char_idx]=incoming_char ;
  }
  if ( incoming_char_idx > -1){
    incoming_char_idx++;
    incoming_char_buff[incoming_char_idx]='\0';
    Serial.print("Cell Said : ");
    Serial.println(incoming_char_buff);
  }
  cell.flush();
  isprintline = 0 ;
}
void do_ser(){
  Serial.println("Reading Serial line");
  delay(100);
  incoming_char_idx= -1;
  while (Serial.available()){
    incoming_char_idx++ ;
    incoming_char=Serial.read();
    incoming_char_buff[incoming_char_idx]=incoming_char ;
  }
  if ( incoming_char_idx > -1){
    incoming_char_idx++;
    incoming_char_buff[incoming_char_idx]='\0';
    Serial.print("You type : ");
    Serial.println(incoming_char_buff);
    cell.println(incoming_char_buff);
    delay(1000);
  }
  isprintline = 0 ;
}



1. First, I test it to connect to my other PC via it's Com Port, and the result is :
a. When at the PC side I do not do monitor (i.e cat /dev/ttyS0) , the script output (at serial monitor window) just fine.
I can send text from PC to arduino and vise versa.
Arduino only detect any input on NewSoftSerial pin only if PC send text

b. When I do monitoring at PC side using --> cat /dev/ttyS0 ... the script output (at serial monitor window) start showing a "garbage"
Arduino always see there is "something" on NewSoftSerial pin ...

2. Second ... I change NewSoftSerial speed to 4800 , and attached my GPS (using cross cable), and the result is : Arduino start getting "garbage".

Attached is screen capture of my serial_monitor when GPS attached.

Kindly please give me your enlightment on how to fix it.

Sincerely
-bino-


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy