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.

Pic18f4550 uart problem

Status
Not open for further replies.

pratheeshprm143

Newbie level 6
Joined
Oct 14, 2010
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,440
Hai

I am using PIC18F4550 with USB (20MHz xtal). When i try to send data through UART, my serial port does not get the actual data that I have send.
When I try to send data 00-FF, only some values are correct (7,8,9, j,k,l,m & n). I think the problem is in my baud rate. I have tried more than twenty configurations from many blogs. But the problem is not fixed. I am using C18 toolkit. My code well worked with proteus simulator. Also the port (PORTB) bits are changed in my hardware. Here is my code and configuration bit settings.

configuration bits.png

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <p18f4550.h>
unsigned int i,j;
void delay(int);
void main(void)
{
    TRISB=0x00;
    PORTB=0X00;
    TXSTA=0x20;
    SPBRG=0x20;
    TXSTAbits.TXEN=1;
    RCSTAbits.SPEN=1;
 
while(1)
{
    TXREG='G';
    while(PIR1bits.TXIF==0);
    delay(100);
    PORTB=~PORTB;
     
}
}
void delay(int d)
{
    for(i=0;i<d;i++)
    {
        for(j=0;j<d;j++)
        {
 
        }
    }
}


I have also tried many SPBRG values for 20MHZ crystal like 1Eh,1Fh,20H,21H and so on(with the equation in data sheet).
 
Last edited by a moderator:

Code:
//MCC18 PIC18F4550   

    TXSTAbits.TX9=0; 
    TXSTAbits.TX9D=0;
    TXSTAbits.SYNC=0; 
    TXSTAbits.TXEN=1;
    TXSTAbits.BRGH=1;
    RCSTAbits.CREN=1; 
    BAUDCONbits.BRG16=0;SPBRGH=0; SPBRG=129;          // 9600KBaud   20Mhz clock
    RCSTAbits.SPEN=1;
 

Attachments

  • PIC18F4550_CONFIG.png
    PIC18F4550_CONFIG.png
    29.4 KB · Views: 69
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top