xbee and RFID eval shield

Hi,

I am using dual SoftwareSerial for both my RFID eval board equipped with SM130 and XBEE S1.

I do realise that if using multiple software serial ports, only one can receive data at a time.
however, i could not get my XBEE S1 to receive any data even i am not using my RFID software serial.

I am doing all this on an arduino uno. XBEE S1 is configured to API mode and tested working with 2 usb dongle.
The RFID sample code is also working. my main purpose here is to use the XBEE to replace the physical connection of the arduino and the computer.

/*
RFID Eval 13.56MHz Shield example sketch v10

Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW

works with 13.56MHz MiFare 1k tags

Based on hardware v13:
D7 -> RFID RX
D8 -> RFID TX
D9 -> XBee TX
D10 -> XBee RX

Note: RFID Reset attached to D13 (aka status LED)

Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the 'Found' LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

*/
#include <SoftwareSerial.h>

#include "XBee.h"
XBee xbee = XBee();


SoftwareSerial rfid(7, 8);
SoftwareSerial nss(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
int parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];


char payload[] = "H";
Tx16Request tx = Tx16Request(0x1234, (uint8_t*)payload, sizeof(payload));
Rx16Response rx16 = Rx16Response();


//INIT
void setup()
{
  Serial.begin(9600);
  Serial.println("Start\n");

  // set the data rate for the SoftwareSerial ports
  nss.begin(9600);
  xbee.setSerial(nss);
  rfid.begin(19200);
  delay(10);
  halt();
}

//MAIN
void loop()
{
  //xbee.send(tx);
  xbee.readPacket(5000);
  Serial.println("here1");
  while(xbee.getResponse().isAvailable())
  {
    Serial.println("msg rxed");
    Serial.print("Frame type: ");
    Serial.println(xbee.getResponse().getApiId(), HEX);
    
    if(xbee.getResponse().getApiId() == RX_16_RESPONSE)
      {
        xbee.getResponse().getRx16Response(rx16);
        Serial.print("Address: ");
        Serial.println(rx16.getRemoteAddress16(), HEX);
        
        Serial.print("Length: ");
        Serial.println(rx16.getPacketLength(), DEC);
        
        Serial.print("Data: ");
       
        for(int i=0; i < rx16.getDataLength(); i++)
         {
             Serial.write(rx16.getData(i));
             Serial.print(" ");
         }
         Serial.println();
         Serial.print("Checksum: ");
         Serial.println(rx16.getChecksum(), HEX);
         break;
      }
    else
    {
      xbee.readPacket(5000);
      continue;
    }
  }
  Serial.println("here2");
 //while(1);
  char in;
    if (in=='1')
    {
      read_serial();
      halt();
//      if (flag !=0)
//      {
//        break;
//      }
    }
}

void check_for_notag()
{
  seek();
  delay(10);
  parse();
  set_flag();

  if(flag = 1){
    seek();
    delay(10);
    parse();
  }
}

void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

int parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
}

void print_serial()
{
  //if(flag == 1){
    //print to serial port
    Serial.print(Str1[8], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[5], HEX);
    Serial.println();
    //print to XBee module
    nss.print(Str1[8], HEX);
    nss.print(Str1[7], HEX);
    nss.print(Str1[6], HEX);
    nss.print(Str1[5], HEX);
    nss.println();
    //delay(100);
    //check_for_notag();
 // }
}

void read_serial()
{
      seek();
      delay(10);
      parse();
      set_flag();
      print_serial();
      //flag--;
      //delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}

void print32Bits(uint32_t dw){
  print16Bits(dw >> 16);
  print16Bits(dw & 0xFFFF);
}

void print16Bits(uint16_t w){
  print8Bits(w >> 8);
  print8Bits(w & 0x00FF);
}

void print8Bits(byte c){
  uint8_t nibble = (c >> 4);
  if (nibble <= 9)
    Serial.write(nibble + 0x30);
  else
    Serial.write(nibble + 0x37);
      
  nibble = (uint8_t) (c & 0x0F);
  if (nibble <= 9)
    Serial.write(nibble + 0x30);
  else
    Serial.write(nibble + 0x37);
}

PLEASE ADVISE!!!

In setup(), you call rfid.begin(), making the rfid instance the active listener.

Then, in loop(), you are expecting xbee to have received something. I can't imagine why.

Your indenting sucks, by the way.

  char in;
    if (in=='1')

A local variable is not initialized. There is no reasonable expectation that the memory address that in gets assigned to will have had a '1' in it.

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

There is nothing in this code that looks like seek() is a reasonable name. There are NO comments anywhere. Renaming the function to g6932() makes as much, or as little, sense.

Hi,

this is the original sample code provided by RFID eval board, and i just did a basic modification to it, hence it looked like a big mess.

thanks for the advice! However, i require both to be able to send and receive. I did call nss.begin() as well, so why wont it become the active listener instead?

I did call nss.begin() as well, so why wont it become the active listener instead?

You can only have one active listener. The begin() call makes the instance the active listener. You call rfid.begin() after nss.begin().

However, i require both to be able to send and receive.

Only one at a time can do that. Decide which one losing data is acceptable, and make the other one the active listener most of the time.

Or get a Mega and stop using SoftwareSerial.

thanks for the advice.

with my current hardware, is there anything i can do to make it work? i spent quite a significant amount of money on these hardware already.

with my current hardware, is there anything i can do to make it work?

I think you already know the answer to that.

i spent quite a significant amount of money on these hardware already.

That's unfortunate. You should have done the research first.