From my calculations, i'd say the issue is excess baud rate error. The value placed in register UxBRG
ultimately determines your baud rate. Since the register's value must be an integer, the value obtained from prescribed baud rate formulas (in the datasheet) are rounded to the nearest integer and placed in the register; there is always some error, the question are 'how much?' and 'Is it tolerable?'. Since you are using FCY/2 (= 72/2 = 36 MHz) as peripheral clock and you're using Standard Speed mode (i.e. BRGH = 0, also evident since you are dividing by 16), then, for 1152000 baud, according to the formula:
UxBRG = (FPB / 16 / BaudRate) - 1
UxBRG = (36000000 / 16 / 115200) - 1 = 18.53 = 18
To calculate how much error we have from truncating 18.53 down to 18,
Baud Rate = FPB / 16 * (UxBRG + 1)
Baud Rate = 36000000 / 16 * (18 + 1) = 118421 // approximate
% Error = ((118421 - 115200) / 115200) * 100 = 2.79 %
Acceptable baud rate error differs depending on the device and if its two devices of the same class speaking to each other (e.g. PIC to PIC) but its generally agreed that 2 % is a good maximum for most cases and 2.79 % exceeds that value. So, to solve this problem, there are 2 ways I can see:
Use 72 MHz as the peripheral clock instead, if possible.
UxBRG = (72000000 / 16 / 115200) - 1 = 38.06 = 38
Baud Rate = 72000000 / 16 * (38 + 1) = 115384
% Error = ((115384 - 115200) / 115200) * 100 = 0.16 %
This error is acceptable.
Change from Standard Speed mode to High Speed mode. This involves setting BRGH
or, using your library, calling OpenUART1
this way:
OpenUART1( UART_EN | UART_NO_PAR_8BIT | UART_1STOPBIT | UART_BRGH_FOUR, UART_RX_ENABLE | UART_TX_ENABLE, (FPB/4/BAUDRATE)-1 );
With this change, the new values are:
UxBRG = (36000000 / 4 / 115200) - 1 = 77.125 = 77
Baud Rate = 36000000 / 4 * (77 + 1) = 115384
% Error = ((115384 - 115200) / 115200) * 100 = 0.16 %
Same error as before, still acceptable.