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

P89LPC932 and serial communication, strange phenomenon

Following set:
Two identical PCBs (my hardware design using the LPC932), one with the "real" MCU, other with connector adaptor to EPM900 board.
My software runs smooth on the emulator. I always send 24 bytes via COM5 (virtual COM port of FTDI232 USB-to-RS232 chip). The MCU processes the 24 bytes, executes a command, some routines and sends 24 bytes back to PC.
The 24 bytes are a certain telegram with a two byte header and a checksum at the end.
So far, so good. As I said, it runs smooth on the emu.
But when I flash the compiled hex file into the LPC932 on the other board and connect this board with USB (COM5), I can send the 24 bytes to COM5, but I receive an error code generated by my firmware telling me the header is wrong.
I found out that the last, the 24th byte, is somehow coming to the first position of the serial input buffer. Example:
PC sends: AA 55 00 FF .... FF 60
hardware should have: AA 55 00 FF ... FF 60
in the 24 byte input buffer, but it has: 60 AA 55 00 FF ... FF
No idea. Code is fine, I worked it out a thousand time. The whole buffer seems to be shifted. I repeat, this runs correct on the emu, which holds the same MCU.

The worst fact is, that sometimes the code in the "real" MCU runs correctly after being connected to supply voltage (USB), sometimes it doesn't. So the code must be ok.

Any clue?

Thanks for any help.

Parents
  • Meanwhile I tried this:

    - changed the declaration of all variables related to ISR and serial reception to VOLATILE XDATA and after this didn't work to VOLATILE IDATA -> no change to the error

    - changed the usage of register banks in ISR (before I had no "using 2" or similiar in the code) -> no change to the error

    - set the NOAREGS directive for all .c files (there is a recommendation to do so in the Keil C51 manual concerning ISRs and function calls) -> no change to the error

    The buffer is now assigned to IDATA (before was DATA, but this has no remarkable effect, it's just to let the compiler use the full range of IDATA), like all other variables. The code works fine in the emulator and in the simulator. But still not in the MCU....

    Perhaps I should try all those things described above together?

Reply
  • Meanwhile I tried this:

    - changed the declaration of all variables related to ISR and serial reception to VOLATILE XDATA and after this didn't work to VOLATILE IDATA -> no change to the error

    - changed the usage of register banks in ISR (before I had no "using 2" or similiar in the code) -> no change to the error

    - set the NOAREGS directive for all .c files (there is a recommendation to do so in the Keil C51 manual concerning ISRs and function calls) -> no change to the error

    The buffer is now assigned to IDATA (before was DATA, but this has no remarkable effect, it's just to let the compiler use the full range of IDATA), like all other variables. The code works fine in the emulator and in the simulator. But still not in the MCU....

    Perhaps I should try all those things described above together?

Children
  • I've fixed it by creating a workaround.
    The first byte coming in is checked to be 0xAA while the byte counter is still zero.
    If not, the counter won't be incremented.

    But the phenomenon still remains...

    There is, somehow, an additional byte coming into the SBUF which, after an interrupt occurred, is read and written into my I/O buffer.

    Anyway, thanks for your help, pals!

  • your code

    ESR = 1; // enable serial interrupt
    REN = 1; // enable serial reception
    while (1)


    I have, for a reason I have forgot (it was definitely needed in one case), the practice of doing the following. Try it
    RI = 0;
    TI = 0;
    ESR = 1; // enable serial interrupt
    REN = 1; // enable serial reception
    while (1)

    Erik

  • I also tried to set both flags to zero. The RI flag has been done before, because I reckoned an additional byte coming in somehow into the SBUF. After your suggestion I also tried TI, both didn't help. Just the workaround brought some success:

    void rx_int (void) interrupt 4 using 1
    {
    	uchar *ptr_c;
            uchar rxtemp;
    
    	if (RI)
    	{
    	   RI = 0;
    	   KB3 = 1;
    	   rxtemp = SBUF;
    	   ptr_c = &io_header; // copy byte by byte to receive buffer
               ptr_c += rxcount;
               *ptr_c = SBUF;
    	   if (rxcount == 0 && rxtemp != 0xAA) rxcount = 0; // check if first byte is AA
               else rxcount++;
    	}
    }

    But I still wonder where this comes from. No hint found in the errata sheets of the LPC932.

  • hi,

    But I still wonder where this comes from. No hint found in the errata sheets of the LPC932.

    Indeed, so you should look at another end:

    I always send 24 bytes via COM5 (virtual COM port of FTDI232 USB-to-RS232 chip).

    Check this piece. Problem might be in there (you know, win$lows, new drivers, VC++ "features" etc).

    Regards,
    Oleg

  • I always send 24 bytes via COM5 (virtual COM port of FTDI232 USB-to-RS232 chip).

    Check this piece. Problem might be in there (you know, win$lows, new drivers, VC++ "features" etc).


    I guess, I mentioned above that I looked at the signal on RxD input with an oscilloscope (single shot). There was and is no leading zero byte transmitted. When a new interrupt from UART occurs, which should only be initiated by a serial transfer in or out (in this case in) and I can see, with the osci, the first byte is AA, so the SBUF must be overwritten with that byte and the interrupt occured will call the isr to read that byte.

    Let's end this here, the workaround is functioning.

    Thanks for all help.