Hello! I am trying to establish serial communication between the PC and the AT89C5131 at a baudrate of 9600. The microcontroller has a clock frequency of 16 MHz. According to the baud rate calculator by Keil, 0xFC is the value to be loaded into the BRL register for generating baud rate closest to 9600. However this is not exact, so mostly garbage values are being transmitted. I have attached my code below; please help me figure out if there is any other way to ensure the transmission and reception does not involve unwanted data. The 8051 echoes whatever is sent from the computer - the code is a slightly modified version of something I found on the Atmel website.
#include "reg_c51.h" char uart_data; void main (void) { SCON = 0x50; BDRCON &=0xEC; BDRCON |=0x0C; BRL=0xFC; ES = 1; EA = 1; BDRCON |=0x10; while(1); } void serial_IT(void) interrupt 4 { if (RI == 1) { RI = 0; uart_data = SBUF; SBUF = uart_data; } else TI = 0; }
please help me figure out if there is any other way to ensure the transmission and reception does not involve unwanted data
use a "baudrate crystal" e.g. 11.0592MHz
Or an even better solution. Since this thread is tagged as an ARM thread - consider selecting a suitable ARM processor and enjoy big nice 32-bit prescale + baudrate + fractional + PLL + peripherial clocking registers and mix and match crystal frequencies, core frequencies, peripherial frequencies, baudrates as needed.
Thank you, I think this is what I'm going to do.
Unfortunately, I don't have a choice in the controller that I'm using. But the controller I'm using the "AT89C5131A-L" allows me to change my crystal frequency.