Generally, I reset a timer every time a new byte comes in. When the=20 timer expires, I consider that to be the end of the packet. That works pretty well for me but in my case, the bytes are fairly=20 close to each other, and the time between packets is much longer than=20 one byte time. This doesn't work if the packets are really close together. dwayne At 10:50 AM 2/2/2014, Andre Abelian wrote: >Hi All, > >I am having hard time to determine the length of uart RX data. the=20 >data length is unknown it is between (100-125 byte) and it is less=20 >then 128 bytes. >in my routine RX ISR clears the RX flag and saves the byte came in=20 >and increases the counter. data_available is not used for now > >void __attribute__((interrupt, no_auto_psv)) _U2RXInterrupt(void) { > > uint8_t data_size_U2; > > IFS1bits.U2RXIF =3D 0; > if (U2STAbits.URXDA =3D=3D 1) > { > U2_RX[new_counter] =3D U2RXREG; // save incoming byte > > counter++; // increment > data_available =3D 1; > GLED_ON; > } > >} > > >the counter contains total number of bytes but the question is how=20 >to check when no more data is coming in? to use the counter. >I was testing with IDEL flag U2STAbits.RIDLE I can see when uart=20 >RX is active the flag is set to 0. now the problem is >even on first receive byte the flag will indicate as busy. so just=20 >using when it is busy is not going to work. >in my case I do not mind to deal with fixed 128 byte every time I=20 >already know the data is some where between >100-125 bytes. the only issue is when there is no data coming in the=20 >interrupt will not occur and counting extra is not going to work. > the counter in ISR knows exact length of bytes came in but I do=20 > not know when to check the counter since I do not know the length of data= .. >i am not sure if I explain clearly. the counter and U2_RX are global=20 >variables. > >any idea or suggestion will appreciate. > >thanks > >Andre --=20 Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax www.trinity-electronics.com Custom Electronics Design and Manufacturing --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .