hello,
I have to communicate USART in P18F4550 micro controller in high baud rate mode. According to pic18f4550 datasheet their is a BRGH bit in a TXSTA register, using this bit we can enable the high speed baud rate. but when i calculate the baud rate value for high speed baud rate mode then the value calculated is more then 8 bit which is greater than the size of SPBRG register. I am using 48 MHZ Chrystel Oscillator for PIC. So please suggest me the way of communicate with the high speed baud rate using PIC18F4550.
Please read section 15 of the data sheet. There are two registers to set the baud rate divider, SPBRG is the lower 8 bits and SPBRGH is the upper 8 bits.
hello,
I have set the SPBRG register for lower 8 bit and SPBRGH register for upper 8 bit, but still my code is not working.
i am showing you my code please read it and give me some suggestion.
here is my serial initialization code.
1. What Baud rate are you trying to use?
2. What is 'serial_packet' defined as? Do you really want to send it 11 times?
3. Are you using interrupts (highly recommended) or just polling the interrupt flags. If polling, is your software running any other routines at the same time?
1. I am using 9600 baud rate.
2. serial packet is just a variable defined for data receive and transmit and it is used only 1 times.
3. i am not using interrupts, my code is working on polling.
Hello, I think you have to set the BRG16 bit of the BAUDCON register to enable the use of SPBRG and SPBRGH in 16 bit mode. I didn't see you set BRG16 in your code so maybe this is the problem?
hello sir,
my code is working fine now.
thank you for that. but can you please suggest me that how did you set SPBRGH=0x04 and SPBRG=0xE1, because according to my data sheet in high speed mode, when i calculate my SPBRG AND SPBRGH value for the baud rate 9600. then i get value 311 in decimal and 137 in hex. but this value did not work in this mode. so can you please tell me how did you calculate it?
The nearest value with BRGH = 0 is 312 (decimal) which gives an error of about 0.16%
With BRGH = 1 the nearest value is 1249 (decimal) which gives 9600 bauds exactly.
The formula is in the table 20-1 of the data sheet, you would be using 16-bit asynchronous mode so the calculation is Fosc/(4 * (n + 1)):
48000000/(4 * (1249 + 1)) = 9600.
If you set BRGH = 0, the '4 *' becomes '16 *' and the resulting number four times smaller.