Pages: [1]   Go Down
Author Topic: Connecting Two Microcontrollers Via Serial RS232  (Read 679 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are the key factors I need to consider when connecting my Mega to a Mcu sending a stream in RS232 format?

This code is not streaming text in my serial window when I run it so I'm trying to figure out what the problem might be.

http://atlas-scientific.com/_files/code/Arduino-sample-code-EZ-COM.pdf

Here is my unit:
http://atlas-scientific.com/product_pages/embedded/flo-30.html

Thanks for any help.
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

post your code please
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

/*
This software was made to demonstrate how to quickly get your Atlas Scientific product running on the Arduino platform.
An Arduino MEGA 2560 board was used to test this code.
This code was written in the Arudino 1.0 IDE
Modify the code to fit your system.
**Type in a command in the serial monitor and the Atlas Scientific product will respond.**
**The data from the Atlas Scientific product will come out on the serial monitor.**
Code efficacy was NOT considered, this is a demo only.
The TX3 line goes to the RX pin of your product.
The RX3 line goes to the TX pin of your product.
Make sure you also connect to power and GND pins to power and a common ground.
Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the baud rate to 38400.
Remember, select carriage return from the drop down menu next to the baud rate selection; not "both NL & CR".
*/



String inputstring = "";                                                       //a string to hold incoming data from the PC
String sensorstring = "";                                                      //a string to hold the data from the Atlas Scientific product
boolean input_stringcomplete = false;                                          //have we received all the data from the PC
boolean sensor_stringcomplete = false;                                         //have we received all the data from the Atlas Scientific product


  void setup(){                                                                //set up the hardware
     Serial.begin(38400);                                                      //set baud rate for the hardware serial port_0 to 38400
     Serial3.begin(38400);                                                     //set baud rate for software serial port_3 to 38400
     inputstring.reserve(5);                                                   //set aside some bytes for receiving data from the PC
     sensorstring.reserve(30);                                                 //set aside some bytes for receiving data from Atlas Scientific product
     }
 
 
 
   void serialEvent() {                                                         //if the hardware serial port_0 receives a char             
               char inchar = (char)Serial.read();                               //get the char we just received
               inputstring += inchar;                                           //add it to the inputString
               if(inchar == '\r') {input_stringcomplete = true;}                //if the incoming character is a <CR>, set the flag
              } 


  void serialEvent3(){                                                         //if the hardware serial port_3 receives a char
              char inchar = (char)Serial3.read();                              //get the char we just received
              sensorstring += inchar;                                          //add it to the inputString
              if(inchar == '\r') {sensor_stringcomplete = true;}               //if the incoming character is a <CR>, set the flag
             }



 void loop(){                                                                   //here we go....
     
  if (input_stringcomplete){                                                   //if a string from the PC has been recived in its entierty
      Serial3.print(inputstring);                                              //send that string to the Atlas Scientific product
      inputstring = "";                                                        //clear the string:
      input_stringcomplete = false;                                            //reset the flage used to tell if we have recived a completed string from the PC
      }

 if (sensor_stringcomplete){                                                   //if a string from the Atlas Scientific product has been recived in its entierty
      Serial.println(sensorstring);                                            //send that string to to the PC's serial monitor
      sensorstring = "";                                                       //clear the string:
      sensor_stringcomplete = false;                                           //reset the flage used to tell if we have recived a completed string from the Atlas Scientific product
      }
 }


Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

From that Atlas link

Quote
Simple RS-232 connectivity (voltage swing 0-VCC)

They obviously have no idea what RS-232 is. They are using async serial but not RS-232. Lucky for you because the RS-232 voltage levels could blow up the Arduino.

I'm not overly familiar with serialEvent() but I think the code looks OK. What about your wiring and terminal setup?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm not overly familiar with serialEvent()

from HardwareSerial.cpp

Code:
void serialEventRun(void)
{
#ifdef serialEvent_implemented
  if (Serial.available()) serialEvent();
#endif
#ifdef serialEvent1_implemented
  if (Serial1.available()) serialEvent1();
#endif
#ifdef serialEvent2_implemented
  if (Serial2.available()) serialEvent2();
#endif
#ifdef serialEvent3_implemented
  if (Serial3.available()) serialEvent3();
#endif
}

called from main()

Code:
#include <Arduino.h>

int main(void)
{
init();
#if defined(USBCON)
USB.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
Not a "multitasking background event" but checked once per loop and it won't interfere with your loop code ..
Never used it, as it gives no clue about the amount of data available --> http://arduino.cc/forum/index.php/topic,139353.msg1046447.html#msg1046447
« Last Edit: December 27, 2012, 11:05:47 am by robtillaart » Logged

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, it sounds like there is something funky going on with the manufacturer's code.

I guess I'll start something new using the Serial Library just to read the data stream coming in from the Atlas board. I'll post my results to conclude the thread.

Thanks for all your feedback.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Never used it, as it gives no clue about the amount of data available
But you are, of course, free to call Serial.available() to learn that.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, problem solved. I don't know what I did different this time around to make it work but here is what I changed

1. I have an Arduino Uno and an Arduino Mega 2560. The Mega seems to be working now (I see streaming data on the serial port)
2. I connected both grounds on the FLO-30 controller



* Mega with Flo-30.jpg (1581.28 KB, 3264x1836 - viewed 16 times.)
* EZ_com_mega.zip (1.19 KB - downloaded 4 times.)
Logged

Pages: [1]   Go Up
Jump to: