i tried to send data, through serial data communication, from one Microcontroller[Atmel 8052 - AT89c52] to another Microcontroller[Atmel 8052 - AT89c52] and back to the source Microcontroller and then display the data on a LCD[16x2]. both the Microcontrollers have 12Mhz crystal and the baud rate is 2,400, and i have calculated the reload value for TH1 in mode 2[auto-reload mode] as, 256-[12E6/(32 x 12 x 2400)]=242.98, which is rounded off to the nearest integer 243. By doing this i am not getting the expected result. the output on the LCD is some junk value[looks v.weird]. what could b the problem???
Hi, You say 'a. The data is going out of the 1st Microcontroller.' All I can see is that 'A' is transmitted to the slave and nothing else - is this what you intended?. In the intr routine, for processing if(TI ==1), you should NOT (and cannot) read SBUF to determine what has just been transmitted as you are reading what SBUF has received (if anything) and thus it may be completly different data to that that you have transmitted! You say 'b. The data is being recived by the 2nd Microcontroller.', from above only one character the 'A' is received by the slave but when you process if (RI ==1) you dont bother reading what you have received to transmit it back out, so move the 'val=SBUF; SBUF=val;' from if(TI==1) to the if(RI==1) section of the code. From the problems detailed in 'a.' and 'b.' above, 'c.' and 'd.' are not true! There are other things that are wrong with your code but if you correct these points above then you should be much further along with your program, but if you still need further help once you have made any revisions then post the revised code and i will try to offer further help. Hope this helps, Mark. P.S. An after thought, is the h/w also correct and is TX linked to RX on the opposite micro?
The nugget of wisdom here is Mr, Neil's dissection of the problem. You need to slice this loaf of bread into edible portions, and it is a sizeable loaf. That being said, let me get to your question. You wonder if there is a baudrate mismatch between the two micros because of the rounding error. That error is the same between the two devices so it really comes down to the two crystals, usually a tight tolerance so your problem probably lies elsewhere but ... If a man's best friend is his dog, an EEs best friend is his scope, so get out yours and connect the TX line of micro #1 to the scope channel #1 and trigger on it. Set up your code to periodically ( timer # whatever ) transmit 0xAA or 0x55. Measure the pulse width of an individual bit. Do the same for micro #2. Compare the widths. They WILL be within the % tolerance specified in the micro datasheet. If not set the timer 1 value for double ( or half ) the baudrate and remeasure, is the measured value double or half? If the error is here( which it probably isn't) double check the crystal, timer setup, capacitors, etc. That said, have you compared the timing specs of the LCD display to your routines above? those device are typically quite slow. Have you tried a loopback connection on micro #1? How do you REALLY know a micro is transmitting or receiving the right byte? Have you used a scope or a port bit as a TX-RX comparison flag?
hai, thanks Mark. And the h/w connection is properly made, i.e, the Tx and Rx of the 1st Microcontroller are connected to the Rx and Tx pin, respectively, of the 2nd Microcontroler.