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.
This is a follow-up question from my previous thread regarding the sending of serial data from one 8051 to another. http://www.keil.com/forum/docs/thread4180.asp Although I have enabled to have one 8051 send out data (delayted byte by byte) while the other end recieves it by polling method, but it is unreliable. ie sometimes it can work but sometimes it cannot. Interestingly, it always work when I try it for the first time after I've downloaded the program into the 8051. Subsequently, when I reset both the 8051, the data will not be successfully recieved by the recieving end. Im quite puzzled why is this so as technically speaking, it does not make a difference as the behavoir of the program will still be the same after system reset. Am I missing out something on the hardware side?
Firstly, are you sure that the transmitter is really transmitting what you think it is? Are you monitoring the comms traffic with a PC or protocol analyser? Secondly, are you using the same clock frequency and baudrate reload value at each end? If not, what are you using? Thirdly, please post a complete program that demonstrates the problem. We can only make guesses until you do this. The snippet you have posted is obviously not what you are really using - the main program calls "slipdev_char_poll()" but you have shown a function called "char_poll()". CUT and PASTE the code from your program to avoid mistakes. Stefan
1) Yes. I have verified that the transmitter is sending out the correct bytes by connecting it to the PC serial port. For testing its just sending 0x01,0x02 and 0x03 repeatedly. I have also deliberately delayed the sending so that there is a delay after each time a byte is sent to allow time for the reciever to read it. 2)Yes. Both 8051 have the exact same configurations. 3)Apologise for the confusion. The code I used is what I have posted. Actually wanted to make things easier for readers by changing the function name to something more generic but missed out the 2nd part. Anyway, here it is again.
char slipdev_char_poll(char *chr){ if (RI==1){ //Character is available *chr = SBUF; RI = 0; return 1; }else{ //Character not available return 0; } }
char c; while(1){ if (slipdev_char_poll(&c)){ switch(c){ case 0x03: //Do something break; case 0x02: //Do something break; case 0x01: //Do something break; } } }