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 support@ccsinfo.com

read RS232 more than one time?

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



Joined: 25 May 2007
Posts: 16

View user's profile Send private message

read RS232 more than one time?
PostPosted: Tue Jul 29, 2008 9:16 am     Reply with quote

hi;
i am using RFID reader that send the ID by RS232.
i used PIC18F458 and 4MHz crystal to read this data, and then compare it with saved one, the program works perfectly on the simulation but on real time the program work for one time only( the program still running but the PIC read one time only from the reader) can you help me to finde how can i read more than one time ??
thank you
my code
Code:
#include<18f458.h>
#use delay(clock=4000000)
#fuses noprotect,nowdt,nolvp,xt
#use rs232(baud=9600, xmit=PIN_c6,rcv=PIN_c7)
#include<lcd.c>

int value=0,i=0;
int8 id[4];

#int_rda
rda_isr()
{
value = getc();
printf(lcd_putc,"%c",value);
id[i]=value;
i++;
}


main()
{
delay_ms(500);
lcd_init();
enable_interrupts(int_rda);
enable_interrupts(global);
lcd_gotoxy(1,1);
set_tris_e(0x00);
output_e(0x00);

while(1)
{
if(i>3)
{
 if((id[0]==52 && id[1]==57  && id[2]==55  && id[3]==57) ||(id[0]==52 && id[1]==57 &&
    id[2]==56 && id[3]==48))
    {
    output_low(pin_e2);
    delay_ms(50);
    output_high(pin_e1);
    i=0;
    id[0]=0;
    id[1]=0;
    id[2]=0;
    id[3]=0;
    delay_ms(500);
    output_low(pin_e1);
    }
    else
    {
    output_high(pin_e2);
     output_low(pin_e1);
     delay_ms(500);
     output_low(pin_e2);
    }
    i=0;
}
   
}}

_________________
A.T.N
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Jul 29, 2008 9:46 am     Reply with quote

The problem is in the interrupt handler code.
Receiving data at @9600 bauds implies that one char is arrieving every 1.04 ms, hence
it is not a good practice to write the LCD after received every char. Take out the printf(LCD)
function of the interrupt and put it in the main().

1)The clue is, inside the interrupt store only the received chars and detect the End of String
character. Then -in main- use the printf(LCD) function to show the received data in the display.

2)Add ERRORS in the #use rs232(........, ERRORS) directive.


Humberto
Ttelmah
Guest







PostPosted: Tue Jul 29, 2008 9:53 am     Reply with quote

First,add 'ERRORS' to your #use RS232 line.
Second add a limit check to 'i' in the interrupt.
Now, tell us what the port E lines 'do'?. Also how frequently the device sends the ID?.
Once you see the ID, you are toggling various line combinations, and pausing for half a second before looping back to try again. If the ID comes more often than once evey half second, the code may have received more than one ID in this time. The buffer will then have overflowed, and data will have been lost. If the wanted ID is found, you reset 'i' immediately, while if the ID is not one of the tested ones, i is not reset till after half a second. In the second case, if even five characters arrive in half a second, there will be an overflow...

Best Wishes
ahmad-al3omar



Joined: 25 May 2007
Posts: 16

View user's profile Send private message

thank you too
PostPosted: Tue Aug 05, 2008 1:21 am     Reply with quote

Ttelmah wrote:
First,add 'ERRORS' to your #use RS232 line.
Second add a limit check to 'i' in the interrupt.
Now, tell us what the port E lines 'do'?. Also how frequently the device sends the ID?.
Once you see the ID, you are toggling various line combinations, and pausing for half a second before looping back to try again. If the ID comes more often than once evey half second, the code may have received more than one ID in this time. The buffer will then have overflowed, and data will have been lost. If the wanted ID is found, you reset 'i' immediately, while if the ID is not one of the tested ones, i is not reset till after half a second. In the second case, if even five characters arrive in half a second, there will be an overflow...

Best Wishes


i add errors and change the limit of the variable ( i ) and the comparing value the system works very good.
thank you again.
_________________
A.T.N
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