PIC usart problem

General Robotics Forum - All aspects of robots and their applications. 

Bookmark this page:  YahooMyWeb Yahoo!  Google Google  Windows Live Favorites Windows Live  del.icio.us del.icio.us  digg digg  Add to Netscape Netscape
Subject Author Date
PIC usart problem ali.keles 06-26-2006
---> Re: PIC usart problem Wayne C. Gramli...06-26-2006
  ---> Re: PIC usart problem Wayne C. Gramli...06-26-2006
If you were  Registered and logged in, you could reply and use other advanced thread options
Posted by on June 26, 2006, 10:52 am
Hi everyone,
I am having a big trouble with my PIC's serial communication. I have
codes like these:
GPS:
            CALL     set4800
A0:         CALL RCread
            CALL    TXsend
            XORLW    'G'
            BNZ     A0

     MOVLW    0XFF
            MOVWF    PORTA
            RETURN
I have incoming messages and I want to take the one which starts
with 'G', so I write these simple codes. Althoug I have sentences which
starts with 'G', PortA never gets FF. I tried these codes with Proteus
and it works. But it doesnt work with my pic16f877 in my circuit. From
TX output I get the bytes which I sent from RC, I see that there are
G's in RC but they dont make the port A to be FF. Please hellllppppp
me.
Here are my functions:
RCread: bcf STATUS,RP0 ; Select Bank 0.
getc1 btfss PIR1,RCIF     ; Skip if RC int flag set
     goto getc1 ; Try again
     movf     RCREG,W ; Read the character
     bcf PIR1,RCIF ; Clear the interrupt flag
     return


TXsend     bcf STATUS,RP0 ; Select Bank 0.
putc1         btfss PIR1,TXIF ; Skip if TXbuffer empty
     goto putc1 ; Try again
     movwf TXREG ; Write it!
     bcf STATUS,RP0 ; Select Bank 0.
         return
set4800:    bsf        STATUS,RP0
            MOVLW    D'51'
            MOVWF    SPBRG
            movlw 0xA4 ; CSRC/TXEN (Internal clock, 8 bit mode,
Async
;operation,
High Speed)
            movwf TXSTA ; Write to TX control register.
            BSF        TXSTA,BRGH
            BCF        STATUS,RP0                 ;
            RETURN


Posted by dan michaels on June 26, 2006, 4:23 pm

ali.keles@gmail.com wrote:
> Hi everyone,
> I am having a big trouble with my PIC's serial communication. I have
> codes like these:
> GPS:
>             CALL     set4800
> A0:         CALL RCread
>             CALL    TXsend
>             XORLW    'G'
>             BNZ     A0
>      MOVLW    0XFF
>             MOVWF    PORTA
>             RETURN
> I have incoming messages and I want to take the one which starts
> with 'G', so I write these simple codes. Althoug I have sentences which
> starts with 'G', PortA never gets FF. I tried these codes with Proteus
> and it works. But it doesnt work with my pic16f877 in my circuit. From
> TX output I get the bytes which I sent from RC, I see that there are
> G's in RC but they dont make the port A to be FF. Please hellllppppp
> me.
> Here are my functions:
> RCread: bcf STATUS,RP0 ; Select Bank 0.
> getc1 btfss PIR1,RCIF     ; Skip if RC int flag set
>      goto getc1 ; Try again
>      movf     RCREG,W ; Read the character
>      bcf PIR1,RCIF ; Clear the interrupt flag
>      return
> TXsend     bcf STATUS,RP0 ; Select Bank 0.
> putc1         btfss PIR1,TXIF ; Skip if TXbuffer empty
>      goto putc1 ; Try again
>      movwf TXREG ; Write it!
>      bcf STATUS,RP0 ; Select Bank 0.
>          return
> set4800:    bsf        STATUS,RP0
>             MOVLW    D'51'
>             MOVWF    SPBRG
>             movlw 0xA4 ; CSRC/TXEN (Internal clock, 8 bit mode,
> Async
> ;operation,
> High Speed)
>             movwf TXSTA ; Write to TX control register.
>             BSF        TXSTA,BRGH
>             BCF        STATUS,RP0                 ;
>             RETURN


Hi Ali. There appear to be at least a couple of problems with your
code.

First, you didn't say what crystal freq you're using, but your value of
51D into SPBRG suggests you're trying to use 19.2 with a 16mhz xtal.

Secondly, you didn't explicitly configure the UART receiver. You need
to put some value into RCSTA.

Third, you need to configure the "direction" reigisters of BOTH port A
and also Port C UART pins 6 [input] and 7 [output].

Also, be aware that port A has only 6 pins so you'll never see FFh
there, and also that port A4 is open-drain and requires a pullup
resistor in order to see a "1".

You should probably also "explicitly" configure the port A pins for
digital I/O and not analog I/O, by setting the ADCON0 and ADCON1
registers, if not using them for A/D conversions.

It helps to have another routine called "setup" at the beginning that
explictly goes around and configures every I/O pin on the chip, as well
as other critical registers like PIE and the interrupt flags, etc. Then
you won't forget which condition these pins come up in at boot-up time.


- dan michaels
www.oricomtech.com
====================


Posted by dan michaels on June 26, 2006, 9:14 pm

> Third, you need to configure the "direction" reigisters of BOTH port A
> and also Port C UART pins 6 [input] and 7 [output].


Oops, RC7 should be an input and RC6 an output.


Posted by Wayne C. Gramlich on June 26, 2006, 8:48 pm
ali.keles@gmail.com wrote:
> Hi everyone,
> I am having a big trouble with my PIC's serial communication. I have
> codes like these:

[snippage]

You need to initialize the RCSTA register along with the TXSTA
registers. You need to set both TRISC<7:6> to 11. Here is the
quote from PIC16F877 spec. sheet.

Bit SPEN (RCSTA<7>), and bits TRISC<7:6>, have to
be set in order to configure pins RC6/TX/CK and RC7/
RX/DT as the Universal Synchronous Asynchronous
Receiver Transmitter.

Tell us the values you stuff into the following registers:

TRISC:
RCSTA:
TXSTA:
SPBRG:

Also, we need to know your crystal frequency and desired baud
rate (4800 baud?)

Also, it is not prudent to ignore the FERR and OERR bits
in RCSTA when receiving since either error can cause the
USART to lock up. If either of those bits are set, you
need to toggle CREN. My PIC ASM is rusty, but something like:

BTFSS RCSTA, FERR
BTC RCSTA, CREN
BTFSS RCSTA, OERR
BTC RCSTA, CREN
BTS RCSTA, CREN

While the UART does not use the any A/D pins, it is prudent
to disable the A/D converter until after you get your basic
UART working.

ADCON0 = 0
ADCON1 = 15

-------------------------------------------

After you have done all of that, let us know if you are still
having problems.

-Wayne

Posted by Wayne C. Gramlich on June 26, 2006, 10:52 pm

> Also, it is not prudent to ignore the FERR and OERR bits
> in RCSTA when receiving since either error can cause the
> USART to lock up. If either of those bits are set, you
> need to toggle CREN. My PIC ASM is rusty, but something like:
>
> BTFSS RCSTA, FERR
> BTC RCSTA, CREN
> BTFSS RCSTA, OERR
> BTC RCSTA, CREN
> BTS RCSTA, CREN

Oops, I got the polarity of the skip instructions backwards,
it should be:

BTFSC RCSTA, FERR
BTC RCSTA, CREN
BTFSC RCSTA, OERR
BTC RCSTA, CREN
BTS RCSTA, CREN

That's why I don't write in assembler very often, I make
too many mistakes.

-Wayne

Similar ThreadsPosted
I2C and usart together on ATMega8 October 7, 2006, 9:46 am
video cam problem December 8, 2006, 5:54 am
pic16f876a problem June 6, 2008, 9:23 pm
Re: Motor Speed Problem July 22, 2005, 3:12 am
Re: Motor Speed Problem July 23, 2005, 12:03 pm
stepper driving problem! February 23, 2006, 11:33 pm
fanuc robot problem March 8, 2006, 2:44 am
Inverse kinematics problem for CRS F3 July 24, 2007, 4:51 pm
DC Motor Controller Problem October 18, 2007, 6:57 am
Astar algorithm, problem December 5, 2009, 6:11 pm

The site map in XML format XML site map
other useful resources:
Official Robosapien Website
Lego Mindstorms Website

Contact Us | Privacy Policy