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

cannot read/store my SBUF value received

Sir, I am having trouble in saving the data received from the rxd of 89c52. when i debug the program and i checked the values and changed the SBUF value and on further checking the values of the temp=SBUF the temp value is still on 0.

unsigned char temp;
void serial_read()      // read byte
{
        while(RI==0);
        temp=SBUF;
        RI=0;
}

and there is a doubt that if we return the SBUF value this is not working.

unsigned char serial_read()
{
 while(RI==0);
 return SBUF;
}

Thanks in advance.

Parents
  • I think this post got off on the wrong foot and Per and Erik muddied the waters. What they both posted is true. Both the xmit and the receive SBUF exist at the same SFR address. You can't write to the receive SBUF and you can't read the xmit SBUF.

    But the SBUF is very seldom the problem in USART communication. Forget that approach. When you write to the xmit SBUF the data goes out period if you have the clocks enabled, etc.

    So the first thing to do is to connect to a terminal such as Hyperterminal and look for data. If you get garbage data or no data you have a place to start debugging. Do you have a scope or logic probe of some type. Take a look a the data lines. Are you getting any signal transmission? Are you getting garbage data out? If so, you probably have a problem with baud rate settings.

    The same approach with receive data. Are you getting data on the receive RX pin? Have your buddy punch the 'U' key over and over while you look for signals on the RX pin.

    Are you receiving data on the RX pin? Are you using some type of eval board or a target board that you have fabricated? If you are using an eval board have you checked to see if there are jumpers or switches to set?

    We could go on and on with this but you need to put a little more effort in asking more direct questions. Not questions like why can't I read the SBUF? Tell us what you have tested and verified.

    The Keil examples have a number of good examples for serial UART communications. Have you tried any of the these examples?

    From the simulator/debugger you can redirect serial communications out the PC serial port if you have a serial port on you PC. Half my PC no longer have serial ports.

    What all this verbage is saying is move on past the SBUF. The chip hardware works. You don't need to trouble shoot the chip. You need to trouble shoot the target board and your software.

    Bradford

Reply
  • I think this post got off on the wrong foot and Per and Erik muddied the waters. What they both posted is true. Both the xmit and the receive SBUF exist at the same SFR address. You can't write to the receive SBUF and you can't read the xmit SBUF.

    But the SBUF is very seldom the problem in USART communication. Forget that approach. When you write to the xmit SBUF the data goes out period if you have the clocks enabled, etc.

    So the first thing to do is to connect to a terminal such as Hyperterminal and look for data. If you get garbage data or no data you have a place to start debugging. Do you have a scope or logic probe of some type. Take a look a the data lines. Are you getting any signal transmission? Are you getting garbage data out? If so, you probably have a problem with baud rate settings.

    The same approach with receive data. Are you getting data on the receive RX pin? Have your buddy punch the 'U' key over and over while you look for signals on the RX pin.

    Are you receiving data on the RX pin? Are you using some type of eval board or a target board that you have fabricated? If you are using an eval board have you checked to see if there are jumpers or switches to set?

    We could go on and on with this but you need to put a little more effort in asking more direct questions. Not questions like why can't I read the SBUF? Tell us what you have tested and verified.

    The Keil examples have a number of good examples for serial UART communications. Have you tried any of the these examples?

    From the simulator/debugger you can redirect serial communications out the PC serial port if you have a serial port on you PC. Half my PC no longer have serial ports.

    What all this verbage is saying is move on past the SBUF. The chip hardware works. You don't need to trouble shoot the chip. You need to trouble shoot the target board and your software.

    Bradford

Children