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

Data recieved from UART does not latch on any Port

I have this very strange problem. I am recieving data on UART and when I try to throw the data on any port, it shows up mometarily on the port and then all the port goes to zero. I do not understand this but the code works fine in debugger with SIN command.Here is the code if any one want to give a suggestion .Thanks


#include "REG51CC01.h"

void serial_IT(void) interrupt 4 using 2
{

char uart_data=0;

if (RI == 1)
{
RI = 0; // clear reception flag
uart_data = SBUF; // Read data
P2=uart_data; //Output recieve data

}


}



void main (void)
{
unsigned char del=0;
SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */
T2CON &= 0xF0; /* EXEN2=0; TR2=0; C/T2#=0; CP/RL2#=0; */
T2CON |= 0x30; /* RCLK = 1; TCLK=1; */
TH2=0xFF; /* init value */
TL2=0xFD; /* init value */
RCAP2H=0xFF; /* reload value, 115200 Bds at 11.059MHz */
RCAP2L=0xFD; /* reload value, 115200 Bds at 11.059MHz */
ES = 1; /* Enable serial interrupt */
EA = 1; /* Enable global interrupt */
TR2 = 1; /* Timer 2 run */

while(1);

}

Parents
  • looked at youyr code twice, saw nothing bad.

    1) I take it you do not hav any external memory
    2) are you absolutotally sure that no zero bytes come down the pipe, try just for kicks

    if (RI == 1)
    {
      RI = 0; // clear reception flag
      if (uart_data == 0)
      {
        uart_data = SBUF; // Read data
        P2=uart_data; //Output recieve data
      }
    }
    If that works, you have 2) above
    Erik

Reply
  • looked at youyr code twice, saw nothing bad.

    1) I take it you do not hav any external memory
    2) are you absolutotally sure that no zero bytes come down the pipe, try just for kicks

    if (RI == 1)
    {
      RI = 0; // clear reception flag
      if (uart_data == 0)
      {
        uart_data = SBUF; // Read data
        P2=uart_data; //Output recieve data
      }
    }
    If that works, you have 2) above
    Erik

Children
  • Thanks for your reply, Eric.

    Yes, I do not have any external memory.
    Secondly, I also thought there may be something following my first data that overwrites it so I counted the number of interrupts and there is exactly one interrupt after I send one data to UART.

    Now here is another strange thing, if I run this program with if statement in interrrupt routine as shown in the following program it works just fine. But I guess by using this approach I can not recieve zero on UART.

    #include "REG51CC01.h"

    void serial_IT(void) interrupt 4 using 2
    {

    char uart_data=0;

    if (RI == 1)
    { /* if reception occur */
    RI = 0; /* clear reception flag for next reception */
    uart_data = SBUF; /* Read receive data */
    if(uart_data)
    P2=uart_data;

    }


    }


    void main (void)
    {
    unsigned char del=0;
    SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */
    T2CON &= 0xF0; /* EXEN2=0; TR2=0; C/T2#=0; CP/RL2#=0; */
    T2CON |= 0x30; /* RCLK = 1; TCLK=1; */
    TH2=0xFF; /* init value */
    TL2=0xFD; /* init value */
    RCAP2H=0xFF; /* reload value, 115200 Bds at 11.059MHz */
    RCAP2L=0xFD; /* reload value, 115200 Bds at 11.059MHz */
    ES = 1; /* Enable serial interrupt */
    EA = 1; /* Enable global interrupt */
    TR2 = 1; /* Timer 2 run */

    while(1);

    }

  • Can you post the assembly code generated for the interrupt handler?

    I have a vague recollection of a couple of recent bug fixes that had to do with comparing bits and integers. What does

    if (RI == 1)

    compile into? What about

    if (RI)

    ?