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???
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?