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 serial receiption

Hi My project involves serial transmission and serial reception. I have dumped the suitable code for the micro-controller(AT9S52) at the transmitter and the receiver. I have simulated both the codes successfully in keil u vision3. The micro-controller is transmitting the serial data without any problem. But the mc at receiver is not receiving any data. I'm not able to understand what the problem is...

My code at the receiver is as follows. The job of the receiver is to just receive any serial data coming. Please help me if there's any amendment I've to make...

#include"reg51.h"
void initialize()
{
SCON=0x50;
PCON=0X80;
TMOD=0x20;
TL1=0x00;
TH1=0x5D;
TR1=1;
RI=0;
}
void main()
{
int rdata;
while(1)
{
initialize();
while(RI==0);
rdata=SBUF;
RI=0;
P2=rdata;
}
}

Parents
  • Iniialization of the serial port inside the loop is most definitely a big no-no. Do you really think the UART can keep itself in a working state and handle incomming data when you reinitialize it?

    But why should we - again - check your code, when you haven't even thought it valuable to test your code before coming back and request more help? Don't you think that _you_ should be the most involved individual in solving the problems?

    Other things to think about:
    - whenever you design a program with UART communication, you should try an initial transmission of characters just to allow you to verify the correct baudrate with an oscilloscope. Than you can remove the transmission and know that the UART will also have correct baudrate for receiving data.
    - you haven't mentioned any testing at all. But when UART communication doesn't work, you really should always check with an oscilloscope that you do get serial data with correct baudrate to the receive pin of the processor, so there are any data for the UART to pick up. It would be bad to spend too much time fighting the source code in case the signals are accidentally routed wrong...

Reply
  • Iniialization of the serial port inside the loop is most definitely a big no-no. Do you really think the UART can keep itself in a working state and handle incomming data when you reinitialize it?

    But why should we - again - check your code, when you haven't even thought it valuable to test your code before coming back and request more help? Don't you think that _you_ should be the most involved individual in solving the problems?

    Other things to think about:
    - whenever you design a program with UART communication, you should try an initial transmission of characters just to allow you to verify the correct baudrate with an oscilloscope. Than you can remove the transmission and know that the UART will also have correct baudrate for receiving data.
    - you haven't mentioned any testing at all. But when UART communication doesn't work, you really should always check with an oscilloscope that you do get serial data with correct baudrate to the receive pin of the processor, so there are any data for the UART to pick up. It would be bad to spend too much time fighting the source code in case the signals are accidentally routed wrong...

Children