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

Problem with SBUF0

I write a C application for the Cygnal C8051F126( and I'm having some problems with writeng data to SBUF0
A simple example in C code is here:

SFRPAGE = UART0_PAGE;
SBUF0 = 0x12;

On disassembler window I see something like this:
MOV SFRPAGE(ox84),#0x01
MOV SBUF1(0x99),#?C_PBP(0x12)

and ... SBUF0 not modified. If I change in to UART0 to UART1 and SBUF0 SBUF1 , - SBUF1 doesn't modified also.

This is not a bug...? What is it?

Thanks in advance,

MVM

Parents Reply Children
  • There are two physical buffers hiding behind the SBUF0 address. If you read SBUF0, you get the value of the receive buffer. If you write SBUF0, you set the value of the transmit buffer. So, you can never read the value that you just wrote into SBUF0; the read comes from a different set of bits than the write.

    This trick of sharing one address is (or at least was) moderately common, especially for simple devices like UARTs and devices of the vintage of the 8051.

  • "There are two physical buffers hiding behind the SBUF0 address:
    If you
    read SBUF0, you get the value of the receive buffer;
    If you
    write SBUF0, you set the value of the transmit buffer."

    This is clearly illustrated in Figs 13-16 of the 80C51 Family Hardware Description (Chapter 3 of "the bible"):
    http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf

    Pages 9-15 of this document (which includesg those figures) describe the 8051 serial interface in detail.