View previous topic :: View next topic |
Author |
Message |
MAKInnovation
Joined: 16 Nov 2010 Posts: 61
|
serial data initialization issue |
Posted: Fri Nov 09, 2012 12:14 am |
|
|
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
|
|
Posted: Fri Nov 09, 2012 2:31 am |
|
|
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: 19538
|
|
Posted: Fri Nov 09, 2012 4:27 am |
|
|
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
|
Solved |
Posted: Fri Nov 09, 2012 5:16 am |
|
|
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: 19538
|
|
Posted: Fri Nov 09, 2012 8:09 am |
|
|
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 |
|
|
|