We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I would like to have my two 89C51RD2 communicate with each other via UART. They are connected such that one TX pin is connected to the other's RX pin and vice versa. I tried sending byte by byte and it is working. However, when I tried to transmit larger amount of data at one go, the receiving end isnt able to read the data. I feel that I am missing something silly. Is the microcontroller able to store the incoming data while I poll and get them byte by byte? Would somebody please advise. Thank you. Cheers
It would be best if you post the code you are using at the receiving end. Stefan
Here is my code used to do the polling whether anything is recieved
char char_poll(char xdata *chr){ if (RI==1){ //Character is available *chr = SBUF; //Store recieved character into variable chr RI = 0; return 1; }else{ //Character not available return 0; } return(chr);
char data_poll(void) { char xdata c; while(char_poll(&c)) { /*Process data byte by byte*/ } }
Your problem is that the second time char_poll() is called the second byte almost certainly won't have arrived in SBUF, so zero is returned causing data_poll() to exit. Bear in mind that at, say, 9600 baud roughly one character arrives per millisecond - char_poll() is being called much faster than that. In your existing reception scheme you would need to wait for RI to go true in char_poll() for some time rather than returning immediately if RI is false. Stefan
You could always do something like this:
while (1) { if (char_poll(&c)) { /* Process data byte by byte */ } }
In that case if I call data_poll() periodically by placing it in an infinite loop, then the problem would not exist isnt it? As the char_poll() will still come in the next time round to read the data. Am I right to say that, a potential problem would be that transmit side is too fast such that before the reciever can retrieve the previous data sent from SBUF, another byte is written to it and hence data is lost?