Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Poblem in enabling the high speed baud rate in PIC18f4550

Status
Not open for further replies.

abhishekdixit

Full Member level 2
Joined
Dec 30, 2011
Messages
124
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
India
Activity points
2,182
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.

Thank you
 

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.

Brian.
 
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.
Code:
void UARTInitilize()
{
    TRISC=0xC0;
    TXSTA=0x24;
    RCSTA=0x90;
    SPBRG=0x37;
    SPBRGH=0x01;
    TXSTAbits.TXEN=1;
    RCSTAbits.SPEN=1;
}

here is my Serial Trans code:
Code:
void UARTtrans()
{
   // unsigned char i=0;
   // for(i=0;i<11;i++)
    {
        TXREG = serial_packet;
        while(PIR1bits.TXIF==0);
        PIR1bits.TXIF=0;
        Delay10TCYx(50);
    }
}

and here is Serial Receive code:
Code:
void UARTReceive()
{
    //unsigned char i=0;
   // for(i=0;i<11;i++)
    {
        while(PIR1bits.RCIF==0);
        serial_packet = RCREG;
        PIR1bits.RCIF=0;
    }
}

so please see it and provide me some suggestion.

Thank You
 

Questions:

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?

Brian.
 

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.

Thank You
 

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?
 

BRG16 has to be set and you can also get more accurate 9600 bauds if BRGH= 1, SPBRGH = 0x04 and SPBRG = 0xE1.

Be aware that the different clock configurations will also influence the speed settings.

I very strongly suggest you use the USART interrupts rather than polling, the code is no more complicated and it avoids all kinds of timing problems.

Brian.
 

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?

Thank You
 

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.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top