CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F4620 get data RX port

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Knight_FlyCn



Joined: 10 May 2013
Posts: 16
Location: Việt Nam

View user's profile Send private message AIM Address

18F4620 get data RX port
PostPosted: Sun May 26, 2013 12:05 pm     Reply with quote

I read data from RX (RFID tag - Reader: RDM6300) by code:
Code:

volatile char StartFlag = 0;
volatile char StopFlag = 0;
char array[12];
int i;

#INT_RDA
void interrupt()
{
   RCIF = 0;
    if (RCREG == 0X02)                    /*  check for start byte               */
    {
      StartFlag = 1;
    }

    if (StartFlag == 1 && RCREG != 0X03)
    {
       array[i] = RCREG;/*  store received data into an array  */
       i++;
    }

    if (RCREG == 0X03)                    /*  10 byte data is received           */
    {
       array[i] = '\0';
      StopFlag = 1;
        i = 0;
    }
}


But don't anything in array[i] . I don't known and who can help me ?

And when I connect PIC with PC. I used code:

Code:


c=getc();



Why I used it for RFID don't working
_________________
Thinh
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun May 26, 2013 12:49 pm     Reply with quote

One thing I notice is Start_Flag, once set, always stays 1

You should fetch RCREG into a temp variable for test

You should test for the end byte second, not last. then
you can remove the end byte test from your data
input routine.

Without more to go on...
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Sun May 26, 2013 12:53 pm; edited 1 time in total
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun May 26, 2013 12:49 pm     Reply with quote

Sorry, can't help.

Your code is neither complete nor compilable, so it's not possible to copy and paste to test.
Could be allsorts of issues, you don't provide enough information.
I suggest you read and follow the forum guidelines.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun May 26, 2013 1:23 pm     Reply with quote

Comments:

RCIF=0;

Does nothing. RCIF _cannot be cleared till the character is read_.
The compiler automatically tries to clear RCIF for you when the routine exits, but this too won't work, because of the next problem.

Big problem is that you must _always_ physically read the byte received. Now a test for equality, won't necessarily read the byte. So when 2 is received the interrupt can't be cleared, and the code will loop for ever.

Use:
Code:

#INT_RDA
void interrupt()
{
  int8 rxchar;
  rxchar=getc();          //now you have read the char
  if (rxchar == 0X02)   // check for start byte
  {
     StartFlag = TRUE;
     i=0; //make sure we start at the beginning
  }
  else
  {
     if (StartFlag)
     {
         if (rxchar == 0X03)
         {
            array[i] = '\0';
            StopFlag = TRUE;
            StartFlag = FALSE;
            i = 0;     
         }
         else
            array[i++] = rxchar;    //  store received data into an array
     }
   }
}

Make the array slightly larger, just in case something unexpected arrives.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group