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.

PIC 18f4520 eusart problem

Status
Not open for further replies.

kemalkemal

Member level 1
Joined
Jan 27, 2013
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,672
Hi all,
I have wrote a small program for usart module at mplabx ide v2.35. I am using Realterm for communication software. Between my development board and usb port of pc there is a USB-serial converter. My problem is: when i send 0x82, i receive 0x22 most of the time. Interesting thing is that; whenever I control my data from the output pin of max232 (just before the USB-serial converter) with an oscilloscope everything seems ok. So i am suspicious on converter thing or Realterm. Here is my code. Any problem can you see?

Code:
LIST	P=18f4520
    INCLUDE	<p18f4520.inc>

RES_VECT    CODE    0x0000
            GOTO    START
INT_VECT    CODE    0x0008
            GOTO    START

    #DEFINE CLK_20MHZ
    EXTERN  P18_usart
    GLOBAL  FLAG,SEND_DATA

    UDATA_ACS
FLAG        RES     1       ;PIC18_usart.asm
SEND_DATA   RES     1       ;PIC18_usart.asm

MAIN_PROG CODE
START

SEND_START
    CLRF    SEND_DATA
    MOVLW   0x82
    MOVWF   SEND_DATA
    CALL    P18_usart
    BRA     SEND_START

    END

Code:
 LIST	p=18f4520
    #INCLUDE	<p18f4520.inc>
    #DEFINE	USART_FLAG  FLAG,1

    GLOBAL	P18_usart
    EXTERN	FLAG,SEND_DATA



    CODE
P18_usart
    BTFSC	USART_FLAG,0
    GOTO	START_SEND      ;USART_FLAG,0=1 ise 

    #IFDEF	CLK_20MHZ   ;Tcy=200ns
    BSF	    TXSTA,BRGH	    ;BRGH=1 , high speed asynch
    MOVLW   .129            ;fosc=20 MHz ---> baud rate 9.6k
    MOVWF   SPBRG;
    #ENDIF

    BCF     TRISC,TX
    BSF	    RCSTA,SPEN	    ;Serial Port enabled.(configures RC7/RX/DT and RC6/TX/CK pins as serial port pins)
    BSF	    TXSTA,TXEN
    BSF     USART_FLAG,0

START_SEND
    BTFSS	PIR1,TXIF           
    BRA 	START_SEND
    MOVFF   SEND_DATA,TXREG
    RETURN
    END

and this is the screen shot.
edaboard1.jpg
 

Just about every time this type of question is asked, it is the BAUD rate is wrong and there can be several causes for that.
What are the config settings? Are you really using a 20MHz Fosc? Is it crystal driven or are you using the internal oscillator?
I admit I don't really know assembler but are you sure that the 2nd code section is actually seeing the "CLK_20MHZ" symbol defined in the first code block? Also why make setting the SPBRG register conditional?
Susan
 

Thanks for the reply susan. I rechecked the BAUD rate and the crystal. But I think it was the "CLK_20MHZ" section that cause the error. After i canceled #DEFINE CLK_20MHZ everything got better.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top