Pages: [1]   Go Down
Author Topic: Multi serial with Arduino Mini  (Read 1314 times)
0 Members and 1 Guest are viewing this topic.
Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I try to have two ports for working and use the standard port only for flash my code.

Code:
NewSoftSerial SerialRFIDreader(2, 3);
NewSoftSerial SerialRS485(4,5);
byte c;


void setup() {               
    // initialize the digital pin as an output.
 
  SerialRFIDreader.begin(4800);
  SerialRS485.begin(4800);
  Serial.begin(4800);

    Serial.println("En route");
    SerialRS485.print("Bonjour");
 
}

void loop()
{
//  while (SerialRFIDreader.available() > 0)
  if (SerialRFIDreader.available() > 0)
  {
    c = SerialRFIDreader.read();
        Serial.println(c);
  }
  Serial.println("C");
  if (SerialRS485.available() > 0)
    {
      Serial.println("D");
      c = SerialRS485.read();
 }

}


I send many charaters on the pin 4, but, become never "D". I think SerialRS485.available() is never bigger then zero... but why ?

Is possible to work so with three ports ?
Logged

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


do you have tx and rx connected correctly (or crossed?)  might need to swap pins. 
Is the 4800 baud correct?
Logged

Rob Tillaart

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

Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Yes, I've right connected tx and rx (crossed first time... smiley-red) .
In a first tim, I've tried with 9600 bauds -> same result.

Is a bug in newsoftserial ?
Logged

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

You can use many instances of NSS in parallel as long as there is not too much traffic as the Arduino is single threading.

just another test sketch.
Code:
NewSoftSerial SerialRFIDreader(2, 3);
NewSoftSerial SerialRS485(4,5);
byte c;


void setup() {               
    // initialize the digital pin as an output.
 
  SerialRFIDreader.begin(4800);
  SerialRS485.begin(4800);
  Serial.begin(4800);

   Serial.println("En route");
}

void loop()
{
  Serial.print("RFID : ");
  Serial.print(SerialRFIDreader.available(), DEC);
  Serial.print("\t\t485 : ");
  Serial.println(SerialRS485.available());
  delay(1000);
}

Do you have a link to the datasheet of the RFIDReader?
Logged

Rob Tillaart

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

Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will try this this evening.
I'll try to disconnect the rfidreader.

I can send with all the ports (I tested yesterday)
Logged

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

Quote
You can use many instances of NSS in parallel as long as there is not too much traffic as the Arduino is single threading.
But, only one instance at a time can receive. NewSoftSerial uses an interrupt to catch the incoming data. When the interrupt fires, the data that is incoming is for the active instance.

Switching which instance is active occurs whenever a method on any instance is called. Changing the active instance changes which interrupt handler is attached, which changes which instance can receive data.

Multiple instances can send easily enough, but only one instance can receive at a time.

It looks like you think you can receive from two instances at once, which is not the case. To do that, you need two (or more) hardware serial ports, which use two (or more) interrupts - one for each hardware port. The only Arduino with multiple hardware serial ports is the Mega.
Logged

Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I begin to understand........


I like read on both ports, but it is not important that is simultaneous.

I can imagine to read on one, work with and after read on the second.

So, You say "Changing the active instance". Can you explain how to do that ?


Thanks
Logged

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

Quote
You say "Changing the active instance". Can you explain how to do that ?
I already did.
Quote
Switching which instance is active occurs whenever a method on any instance is called.
Logged

Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In my sample:
Code:
  if (SerialRFIDreader.available() > 0)
  {
    c = SerialRFIDreader.read();
        Serial.println(c);
  }
  Serial.println("C");
  if (SerialRS485.available() > 0)
    {
      Serial.println("D");
      c = SerialRS485.read();
 }

SerialRFIDreader.available() is a call of method of one instance ?
and
SerialRS485.available() is a call of method of another instance ?

So, the active instance must change ?
Logged

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

Quote
SerialRFIDreader.available() is a call of method of one instance ?
and
SerialRS485.available() is a call of method of another instance ?

So, the active instance must change ?
Yes. Notice, though that data that arrived for the non-active instance was lost, so calling the available method on the inactive instance will always return 0.

Calling them in loop(), as you are doing, will result in neither instance ever being able to receive data.
Logged

Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes,
You are right : only one instance can receive datas.
But I can send without problem to the two instances.

I search how to do...
Logged

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

Quote
But I can send without problem to the two instances.
But I can send without problem from the two instances.
Logged

Suisse
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, right: only from...
Logged

Pages: [1]   Go Up
Jump to: