This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Some characters lost in serial communication

Hello everybody,

My serial ISR is as below. When I send a string to the microcontroller some characters are not received. The characters are lost in a peculiar way. eg. 1234567890123456 is received as 12356789012456 & 6543210987654321 is received as 65421098765321. Exactly 4th & 13th characters are lost in the mentioned 16 character string, not tested further.


void ISR_Serial (void) interrupt 4      //      using 2
{
        unsigned char in_byte;
        if (RI){                                        // If data is received..
                RI = 0;
                in_byte = SBUF;                         // get character in var
                RxBuffer[ RxInChar ] = in_byte;         // save it in the buffer at RxInChar location

                if(RxInChar==RX_BUF_SIZE)               // if buffer full, (care should be taken by sending app)
                        RxInChar=0;                     // then make it 0
                else if(in_byte==0x0D){                 // whether byte was CR?
                        RxBuffer[ RxInChar ] = '\0';    // & replace it     by NULL char
                        RxInChar=0;                     // then make pointer to 0 (for next transmission)
                        if(!pc_mode_active)
                                strcpy(tmpdata,RxBuffer);
                        ser_data_avail=1;               // set data available flag for main routine
                }
                else
                        RxInChar++;                     // increase the location pointer
        }

        if( TxEnabled ){                                // If data is transmitted
                if (TI){                                // if previous byte is finished transmitting
                        TI = 0;

                        if (TxOutChar != TxInChar){     // adjust queue and transmit character...
                                SBUF = TxBuffer [TxOutChar++];
                                TxOutChar %= TX_BUF_SIZE;//%    is the modulus operator
                        }
                        else
                                TxEnabled =     0;      // nothing else to transmit, so disable function...
                }
        }
}


If I comment out following two lines, there is no problem. (though pc_mode_active is true at this time).

                RxInChar=0;                             // then make pointer to 0 (for next transmission)
//              if(!pc_mode_active)
//                      strcpy(tmpdata,RxBuffer);
                        ser_data_avail=1;               // set data available flag for main routine

The baudrate is 115200. RCAP2H = 0xFF & RCAP2L = 0xFD, in VB I've used "115200,N,8,1"

As pc_mode_active is true at default, the 'if loop' should not execute. Similarly there should not be a problem because the code will reach to this point only on receiveing CR which is at the last position. Please help.

Thanks in advance.

Parents
  • Thanks all for your reply.

    As per Per's remarks, the NMEA sentences are really overwritten/missed, because the technique I used is not perfect besides I also enable/disable the ES0 register in main loop. But still it is acceptable to me if I get proper sentence once in 3/4 seconds. Which was achieved at the cost of corruption in PC communication.

    Now I decided to concentrate on the PC communication problem when gps code is still there in ISR.

    One thing I forget to tell you that, I was using baud rate of 9600 for gps whereas 115200 for PC mode. I was changing the value of RCAP2L register on switching. Now I have tried 2 things and the results are as..

    1. I reduced the baud rate in PC comm to 57,600. The missing character problem was solved.

    2. As lowering baud will take long time to read the EEPROM content into the PC, I decided not to lower the baud rate but use the X2 mode which I HAVE NOT USED EARLIER. Now total PC communication is lost??? I have set 115200 in both mcu & PC. Any idea?

Reply
  • Thanks all for your reply.

    As per Per's remarks, the NMEA sentences are really overwritten/missed, because the technique I used is not perfect besides I also enable/disable the ES0 register in main loop. But still it is acceptable to me if I get proper sentence once in 3/4 seconds. Which was achieved at the cost of corruption in PC communication.

    Now I decided to concentrate on the PC communication problem when gps code is still there in ISR.

    One thing I forget to tell you that, I was using baud rate of 9600 for gps whereas 115200 for PC mode. I was changing the value of RCAP2L register on switching. Now I have tried 2 things and the results are as..

    1. I reduced the baud rate in PC comm to 57,600. The missing character problem was solved.

    2. As lowering baud will take long time to read the EEPROM content into the PC, I decided not to lower the baud rate but use the X2 mode which I HAVE NOT USED EARLIER. Now total PC communication is lost??? I have set 115200 in both mcu & PC. Any idea?

Children