9600 baud data transmission on AT89S52, 4 MHz chip

Pairing

I want to transfer data using the AT89S52, and my crystal is 4 MHz. Am I writing the correct baud rate code below? Or do any of you know how to calculate the baud rate?

thanks a lot

void transmit_data() { TMOD = 0x20; TH1 = 0xfd; PCON &= 0x7f; SCON = 0x50; TCON =0x40; while(1) { printf("a"); // transmit a along with CR & LF. } 

}

+4
source share
3 answers

Here is a calculator that will help: http://www.keil.com/c51/baudrate.asp Unfortunately, this shows how weak the choice of a 4 MHz crystal is for standard transfer rates.

+1
source

Match it with some gesstimate values ​​and send 0xAA in a loop. Look at tx o / p with a scope, measure the bit width, and then err ... "optimize" the divisor values. This has some advantages over finding / reading / digesting a huge user guide and calculation:

1) It's faster if you're out of luck.

2) If there is no output, you can fix the inconvenient hardware and / or incorrect assignment of initialization and / or registration of the UART and / or the assignment of contacts before spending time on finding out what you did wrong with the baud rate.

3) It always works, even if the data rate formula in manual mode is less than 100%.

4) When you can see that the output is coming out correctly, but there is still no connection, you can blame it on the cables and / or DCE / DTE and / or Hyperterminal and / or all other things that stop the RS232 from working.

+1
source

The best way to get 9600 bytes is to use 11.0592Mhz Crystal ... 0% error

0
source

Source: https://habr.com/ru/post/1388100/


All Articles