I'm trying to use the USART from a 16C65 to talk to a PC's RS2. I've put
inputs in the RC7 pin in the MPLAB with an stimulus file and with
Asynchornous stimulus, but no char gets in. The code I use to initialize the
USART is:
RS2inic bsf STATUS,RP0 ; *** Banco 1 ***
movlw D'25' ; 9600 Baud
movwf SPBRG
movlw B'00100100'
; ||| +--> BRGH=1 High speed
; ||+----> SYNC=0 Async. transmission
; |+-----> TXEN=1 Enable transmission
; +------> TX8/9=0 8 bits/byte transmission
movwf TXSTA
bcf STATUS,RP0 ; *** Banco 0 ***
movlw B'10010000'
; || +----> CREN=1 Enable reception
; |+------> RC8/9=0 8 bits/byte reception
; +-------> SPEN=1 Enable serial port
movwf RCSTA
And then I wait Interruptions from the USART each incoming char.
The Interruptions initialization is as follows:
; Inicializa las interrupciones
INTinic clrf PIR1 ; TMR2IF=0 Erase int flags
movlw B'00110010'
; || +--> TMR2IE=1 -> Enable tmr2 int.
; |+-----> TXIE=1 -> Enable transm. int.
; +------> RCIE=1 -> Enable receip. int.
bsf STATUS,RP0 ; *** Banco 1 ***
movwf PIE1
bcf STATUS,RP0 ; *** Banco 0 ***
bsf INTCON,6 ; PEIE=1 -> Enable perif. int.
bsf INTCON,7 ; GIE=1 -> Enable general int.
return
(I use a constant timer int and both In and Out USART ints)
ÀWhat's wrong?
Thanks in advance.
-----Mensaje original-----
De: Tom Handley <spam_OUTthandleyTakeThisOuT
TELEPORT.COM>
Para: .....PICLISTKILLspam
@spam@MITVMA.MIT.EDU <PICLIST
KILLspamMITVMA.MIT.EDU>
Fecha: miŽrcoles, 05 de mayo de 1999 14:19
Asunto: Re: PIC16c74
> Aidi, SREN is not relevant in the Asynchronous mode so there is no need
>to clear it. What probably fixed your problem is the clearing and setting
of
{Quote hidden}>the CREN bit which clears the Overrun Error bit, OERR. A better way to
>handle this is to monitor OERR and FERR (Framing Error). If OERR is set,
>clear the error by clearing and setting the CREN bit. If FERR is set, clear
>the error by reading another Byte from the RCREG. While I normally use
>Parallax/CVASM syntax I can provide a MPASM example if someone else does'nt
>jump in.
>
> This leads to a more serious problem. The 16C74 and 16C74A have a known,
>documented, bug when using the high-speed mode (BRGH=1). You simply can not
>get reliable operation with these devices (and the 16C73/73A) when BRGH=1.
>The simple and low cost solution is to use another crystal. With an 8MHz
>crystal you can get 9600 +/- 0.16% with BRGH=0 and SPBRG=12. You can also
>switch to a 16C74B or a 16C77 which work fine with BRGH=1. They are both
>pin-compatible with the 16C77 having 8K of program memory and 368 Bytes of
>data memory compared with 4K/192 Bytes for the 16C74x. Another nice thing
>about the 16C77 is that the upper 16 Bytes of data memory are mapped into
>all four banks.
>
> - Tom
>
>At 02:24 PM 5/4/99 -0400, Aidi Moubhij wrote:
>>Hi Ray,
>>Thank you very much for your help. What you suggested fixed the problem.
>>Now I can move on to the next step. Thank you again.
>>
>>At 01:08 PM 5/4/99 -0400, Ray Gardiner wrote:
>>>Hi Aidi,
>>>Just a couple of things, you should set CREN before clearing SREN,
>>>I also found that toggling CREN after receive to clear any rx errors.
>>>See code below. You also must wait for the byte to actually be received.
>>>
>>>> Hi,
>>>>
>>>>I'm using the code below to receive a byte from the US ART. When I get
the
>>>>byte I display it on the LED's and echo it back.
>>>>This code is not working for me. Can anybody tell me what I'm doing
wrong.
{Quote hidden}>>>> Thanks
>>>>
>>>> list p=16c74
>>>> Title "first aidi Program"
>>>>
>>>> include <P16C74.INC>
>>>>
>>>> org 00h
>>>>
>>>>Start
>>>> clrf PORTB ;Clear PORT_B output latches
>>>>
>>>> bsf STATUS,RP0 ;Go to Bank1
>>>>
>>>> clrf TRISB ;Config PORT_B as all outputs
>>>>
>>>>
>>>> movlw 19h ;Set Band rate (9600 baud @4MHz)
>>>> movwf SPBRG
>>>> movlw b'00100100' ;8-bit transmit, transmitter enable
>>>> movwf TXSTA ;Asynchronous mode, High baud rate
>>>>
>>>> bcf STATUS,RP0 ;Go to Bank0
>>>>
>>>> movlw b'10010000' ;8-bit receive, receiver enabled
>>>> movwf RCSTA ;serial port enabled
>>>>
>>>
>>>; ADDED THE FOLLOWING LINES *****;
>>> ;
>>>RxTest ;
>>> ;
>>> BSF RCSTA,4 ;set CREN
>>> BCF RCSTA,5 ;clear SREN
>>> ;
>>>RxWait ;
>>> BTFSS PIR1,5 ;RxBuffer Full when PIR,5=1
>>> GOTO RxWait ;
>>> ;
>>> BCF RCSTA,4 ;toggle CREN to clear any Rx
>>> BSF RCSTA,4 ;errors. You could choose to
>>> ;handle Rx errors differently
>>> ;for a "real" application.
>>>; *******************************;
>>>
>>>> movf RCREG,W ;Get input data
>>>> movwf PORTB ;Display on LEDs
>>>> movwf TXREG ;Echo character back
>>>
>>>> goto RxTest ; ***Changed here also.
>>>>
>>>> end
>>>
>>>>Aidi Moubhij
>>>Ray Gardiner
.....rayKILLspam
.....hdc.com.au
>>Aidi Moubhij
>