PDA

View Full Version : Usart and interrupt



Maurizio
- 10th January 2006, 05:53
Hello!
I have read a lot of discussions about hserin and interrupt, I'm writing a little code to test how usart interrupt is working but... don't work!
Here is my code:

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 1200
DEFINE HSER_CLROERR 1
GP VAR BYTE ' GP variable
INTCON.7 = 1
INTCON.6 = 1 ' Enable interrupt
PIE1.5 = 1
'
LED VAR PORTC.5
OUTPUT LED
LED = 1
on interrupt goto myint
'
mainprg:
PAUSE 1 'only for test
GOTO mainprg
'
DISABLE
myint:
LED = 0
PAUSE 3000
LED = 1
WHILE RCIF ' Keep reading until RCIF is clear to flush buffer
GP=RCREG
WEND
RESUME
ENABLE

The code put led on, I'm expect to put led off for 3 sec. when I send data to RS232 but don't work.
The hardware is ok, I try with hserin-hserout and is working, only usart interrupt is not working
PIC is a 18F452 at 4 Mhz
Can anyone help me?

Bruce
- 10th January 2006, 06:34
Using these defines does not configure the hardware USART automatically. These USART setup parameters do nothing until you use HSERIN or HSEROUT in your code.

If you don't use one of these commands, then none of the hardware USART library functions are compiled in your code, and there is no code to use the parameters in the DEFINE statements.

Place at least one instance of HSERIN somewhere in your code to compile that portion of the hardware USART library with the rest of your program.

Or manually configure the hardware USART.

RCSTA = $90 would be the bare minimum. This enables the hardware serial port, and continuous receive. If the port isn't enabled, it can't receive inbound data & generate the interrupt.

Maurizio
- 10th January 2006, 17:02
Thanks Bruce for the help, now is working well.
Regards and thanks again
Maurizio

Tissy
- 23rd February 2006, 01:26
Maurizio, could you share what was your updated code was to make your small program work.

I am trying to set-up a USART Interupt on a 18F2550.

Many thanks,

Steve