Searching \ for '[PIC]: USART receive problems' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=usart
Search entire site for: 'USART receive problems'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: USART receive problems'
2001\08\11@172155 by Andy Meng

picon face
Hello,

I have been monitoring the PIClist for a few weeks, and decided to post
about some trouble I am having with the USART on the 16F873. I have written
some code to write to an LCD as the start of a larger project, and I am now
working on the serial communications link. I first print the initialization
message on the LCD, and send the same data out the USART to the PC at the
same time. This works fine, but I can't transmit data back to the PIC from
the PC.

I am using a 16F873 running at 3.4MHz with a TC232 IC as the level
converter. I checked the signals going into the PIC (on RC7) with a 'scope,
and the levels appear to be fine. I am not sure about the actual bit
pattern, but by going up and down the alphabet on the keyboard I can see
binary counting going on, so I think it is sending the right data. I am
using the old "Terminal" program, but I tried Hyperterminal also. It is
running at 1200 baud. I have a troubleshooting LED that should turn on when
it enters the ISR, but it never goes on when I send it characters. Below is
the relevant part of the code:

------------------------------------------
org 0
goto Init

org 4
goto Interrupt

__CONFIG _BODEN_OFF & _CP_OFF & _XT_OSC & _PWRTE_OFF & _WDT_OFF & _LVP_OFF
include "P16F873.inc"

Interrupt:
   bcf           INTCON,GIE
   btfss        INTCON,GIE
   goto        $ - 2
   bsf          PORTB,LED    ; turn on LED
   call         Delay15ms
   call         Delay15ms
   call         Delay15ms
   call         Delay15ms
   bcf         PORTB,LED
   btfsc      PIR1,RCIF       ; see if RX flag is set
   call        RS232_Receive  ; if it is, call RS232_Receive
   retfie

   org 20
Init:
   clrf           INTCON            ; make sure INTCON is cleared
   bsf           INTCON,PEIE   ; turn on interrupts for peripherals
   movlw     0x90
   movwf     RCSTA               ; turn on USART, continuous receive
   bsf           STATUS,    RP0     ; page 1
   clrf          PIE1                     ; clear individual peripheral
interrupt enables
   bsf          PIE1,RCIE          ; turn on USART RX interrupt
   movlw     0x2B
   movwf     SPBRG         ; load 1200 baud into baud rate gen
   movlw     0x20
   movwf     TXSTA         ; turn on serial transmit enable
   bcf          STATUS,RP0     ; page 0
   ; the rest of the LCD init code goes below this

RS232_Receive:          ; called in ISR
   movf       RCREG,w     ; put received data in w
   movwf    RXdata          ; put it in RXdata reg
   call         LCDwrite       ; write char to LCD
   ;movf      RXdata,w      ; put data in w again
   ;xorlw     0x0D             ; see if enter was pressed
   ;btfsc      STATUS,0    ; if it was, go to next instruction
   ;call        ClearLCD      ; clear the display
   return

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

If I am doing something wrong, please let me know what it is and how I
should change it.

TIA,

Andy Meng N8MX

http://www.qsl.net/n8mx


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\08\11@181503 by wzab

flavicon
picon face
On Sat, Aug 11, 2001 at 05:18:34PM -0400, Andy Meng wrote:
>
> Interrupt:
>     bcf           INTCON,GIE
>     btfss        INTCON,GIE
>     goto        $ - 2

I think that sequence HAS to loop forever, have I missed something?
You enter the interrupt service, clear the GIE, and wait until GIE gets
set. What could set the GIE?
--
                               HTH & Regards,
                             Wojciech M. Zabolotny
       http://www.ise.pw.edu.pl/~wzab  <--> spam_OUTwzabTakeThisOuTspamise.pw.edu.pl

Before buying any hardware ask the dealer if it is Open Source friendly!!!
hhtp://http://www.openhardware.org

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\08\11@213426 by Jinx

face picon face
> Interrupt:
>     bcf           INTCON,GIE
>     btfss        INTCON,GIE
>     goto        $ - 2

If you are checking that GIE has been cleared, shouldn't that
be btfsc ?

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\08\12@120654 by Olin Lathrop

face picon face
> Interrupt:
>     bcf           INTCON,GIE
>     btfss        INTCON,GIE
>     goto        $ - 2

Interrupts are already off by the time you get into the interrupt routine.
Nothing will magically re-enable them.

>     bsf          PORTB,LED    ; turn on LED
>     call         Delay15ms
>     call         Delay15ms
>     call         Delay15ms
>     call         Delay15ms
>     bcf         PORTB,LED
>     btfsc      PIR1,RCIF       ; see if RX flag is set
>     call        RS232_Receive  ; if it is, call RS232_Receive
>     retfie

Read the section about interrupts carefully.  You have major misconceptions
here.  For example, this interrupt routine will randomly and asynchronously
appear to trash state in the foreground routine.  After reading and
understanding the manual, see QQQ_INTR.ASPIC at http://www.embedinc.com/pic
as an example interrupt module.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\08\12@224133 by Andy Meng

picon face
Several people have pointed this out - thank you all. It was meant to check
to make sure that GIE was clear before entering the rest of the routine, but
I mixed up BTFSC and BTFSS. When fixed, it worked fine.

I am not concerned about losing data in the foreground when interrupted. I
am just looping and getting interrupted out of the loop. I realize that I
will have to make copies of the registers when more processing is added to
the loop. I have been reading Myke Predko's book (Programming and
Customizing the PICmicro, 2nd Ed), and he explains the way to do this. I
haven't used interrupts before, so the interrupt coding is new to me.

Thanks,
Andy Meng N8MX

{Original Message removed}

2001\08\13@050032 by Vasile Surducan

flavicon
face
I'm not so good to understand quickly what's your problem, but I suggest
to take a look on the picuart.asm
Will help you as it done for me:

http://www.mcgahee.freeservers.com/

Vasile


On Sat, 11 Aug 2001, Andy Meng wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\08\13@063355 by dr. Imre Bartfai

flavicon
face
Hi,

some points besides for GIE (Olin said it the best way):

"The RCREG is a double buffered register ... [so it] can be read twice to
retrieve the two bytes in the FIFO. "

" ... transfers from the RSR register ... are inhibited, so it is
essential to clear error bit OERR if it is set."

(Cited from DS30390E, p. 108).

I hope this helps.

Regards,
Imre


+-----------------------------------------------------------------------+
| The information transmitted is intended only for the person or entity |
| to which it is addressed and may contain confidential and/or          |
| privileged material.  Any review, retransmission, dissemination or    |
| other use of, or taking of any action in reliance upon, this          |
| information by persons or entities other than the intended recipient  |
| is prohibited. If you received this in error, please contact the      |
| sender and delete the material from any computer.                     |
+-----------------------------------------------------------------------+

On Sat, 11 Aug 2001, Andy Meng wrote:

{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\08\13@080833 by Olin Lathrop

face picon face
> Several people have pointed this out - thank you all. It was meant to
check
> to make sure that GIE was clear before entering the rest of the routine,
but
> I mixed up BTFSC and BTFSS. When fixed, it worked fine.

I think you missed the point that this whole loop is unnecessary.  GIE will
be off when the interrupt routine is entered, and will stay off until you
set it on again, usually by using a RETFIE instruction at the end of the
interrupt handler.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, EraseMEolinspam_OUTspamTakeThisOuTembedinc.com, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...