There are basicly three methods: 1. You have some distinct char/pattern in the stream that signals end-of-data. 2. You have a timeout (no data on the line) that singnals end-of-data. 3. Your data has always a fixed lenght. Pick what works for you. The timeout counter should be reset/zeroed in the UART-ISR and the "counting" should be done elsewhere (in main or in another timer-ISR). Jan-Erik. Andre Abelian wrote 2014-02-02 18:50: > Hi All, > > I am having hard time to determine the length of uart RX data. the data = length is unknown it is between (100-125 byte) and it is less then 128 byte= s. > in my routine RX ISR clears the RX flag and saves the byte came in and in= creases 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 to che= ck when no more data is coming in? to use the counter. > I was testing with IDEL flag U2STAbits.RIDLE I can see when uart RX i= s active the flag is set to 0. now the problem is > even on first receive byte the flag will indicate as busy. so just 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 already= know the data is some where between > 100-125 bytes. the only issue is when there is no data coming in the inte= rrupt 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 not kn= ow 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 vari= ables. > > any idea or suggestion will appreciate. > > thanks > > Andre > --=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 .