Electronics > Electronics

RFID reader ID-20 and Axon II?

<< < (2/2)

Okay I've done the casting method and same results.  I think my problem lays in being able to capture all the bytes.  Right now my capture loop stays open when RX != -1 but perhaps that's not reliable or something.  How can i do something similar to the "serial.available" in this code?

--- Code: ---void loop(){

  char tagString[13];
  int index = 0;
  boolean reading = false;


    int readByte = Serial.read(); //read next available byte

    if(readByte == 2) reading = true; //begining of tag
    if(readByte == 3) reading = false; //end of tag

    if(reading && readByte != 2 && readByte != 10 && readByte != 13){
      //store the tag
      tagString[index] = readByte;
      index ++;

  checkTag(tagString); //Check if it is a match
  clearTag(tagString); //Clear the char of all value
  resetReader(); //eset the RFID reader
--- End code ---

I think part of your problem is that your code is trying to do too much at once, making it hard to narrow down where the bug is.

Split up your code into tiny parts, and verify each part one at a time.

Another problem I see with your code is that your index is reset to 0:
int index=0;
whenever uartGetByte(ID20)==-1
(ie it escapes the while loop, and starts at the beginning again)

As your code runs way faster than the UART, this will mean you keep overwriting tagString[0], while the rest of the index remains as random character garbage.

Change this line:

to something like:

--- Code: ---while(readByte != 13){
     //your other if statements here
--- End code ---

(I'm assuming 13 means the RFID number has been completed)

Your problem is here:

--- Code: ---//read from rfid
while(uartGetByte(ID20)!=-1){//do while data recieved non -1 data
    int readByte=uartGetByte(ID20);//Assign byte read to a temp int

--- End code ---

When the first uartGetByte gets something other than -1 you throw it away and then the second uartGetByte problem doesn't have the next character yet and so probably returns -1.
try something like:

--- Code: ---int readByte;
while (readByte = uartGetByte(ID20), readByte !=-1){
    // You've now got the data in readByte

--- End code ---


[0] Message Index

[*] Previous page

Go to full version