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

serial data initialization issue

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



Joined: 16 Nov 2010
Posts: 61

View user's profile Send private message

serial data initialization issue
PostPosted: Fri Nov 09, 2012 12:14 am     Reply with quote

Dear All Friends;
Code:

#int_RDA
RDA_isr()
{
   serial_data1 = fgetc(s1); 
   Line_array [ ++Master_counter ] = serial_data1;
   
   if (Master_counter > 26) Master_counter = 0;
   
   if (Line_array [ Master_counter ]== '}')
   {
      output_toggle(PIN_E1);
      Master_counter = 0;
      Line_array [ Master_counter ] = serial_data1;
   }

}


This a piece of code i wrote to receive data from other device.
Problem occurs when i receive '}' at the middle of the data.

how can i write a code for a data stream with two headers.
'}' + '5' + ----- + '\n'

Regards;
MAK
Mike Walne



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

View user's profile Send private message

PostPosted: Fri Nov 09, 2012 2:31 am     Reply with quote

I'm presuming that '}' is the start character for your header(s).

Could you set up two receive arrays, and toggle between them?

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Fri Nov 09, 2012 4:27 am     Reply with quote

As another comment, presuming the problem is that though '}' is used as the header mark, this can also come inside the packet (where it isn't a header as such), the system would normally be to not look for '}' on it's own as the header marker, but only the character _after_ a line feed.
So, something like:
Code:

#int_RDA
void RDA_isr(void) {
   static int1 have_lf=TRUE; //set so the first line is decoded

   serial_data1 = fgetc(s1);
   Line_array [ ++Master_counter ] = serial_data1;
   if (Master_counter > 26) Master_counter = 0;

   //As a comment, accessing a character in an array using a variable,
   //takes perhaps a dozen instructions. Accessing a fixed variable only one
   //Since you have the received character in 'serial_data1', use this for
   //tests....   
   if (serial_data1=='\n') have_lf=TRUE;
   if (have_lf && (serial_data1== '}')) {
      have_lf=FALSE; //turn off searching for '}', till the next LF
      output_toggle(PIN_E1);
      Master_counter = 0;
      Line_array [ Master_counter ] = serial_data1;
   }
}   


So '}' will only be treated as special, if it is the first one seen after a line feed.
Note also the comment about not using the array if you don't have to. Saves a lot of instructions.

Best Wishes
MAKInnovation



Joined: 16 Nov 2010
Posts: 61

View user's profile Send private message

Solved
PostPosted: Fri Nov 09, 2012 5:16 am     Reply with quote

Thanks Ttelmah
My Problem is solved.
I used the foot character of the sentence first and then the header character as there is no line feed with the stream of data.

Problem is solved....
Thank you very much for your kind help
MAK
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Fri Nov 09, 2012 8:09 am     Reply with quote

I based my 'line feed' comment on the sequence you posted which ended in '\n'. However if there is a foot character instead, then 'glad it worked'.

Best Wishes
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