View Full Version : RX interrupt
Arciure
- 3rd March 2010, 16:30
Hello,
first of all, im new on this forum and i'm from the Netherlands (spelling issue)
since a month, im programming PIC controllers for school. im using a big, pic16f877a device which have alot of functions, including interrupts.
However those interrupts dont work for me. I wrote a code, just to interrupt when serial data is incomming.
Heres the code:
;DEFINE HSER_RCSTA 90h (no function if baud rate is defined)
;DEFINE HSER_TXSTA 20h (no function if baud rate is defined)
define HSER_BAUD 9600
DEFINE HSER_SPBRG 25
define osc 20
Include "modedefs.bas"
ON INTERRUPT GOTO INTERRUPT_HANDLER
INTCON = %11000000
PIE1.5 = 1 ' enable interrupt on usart receive
Main_Loop:
low portd.2
pause 500
hserout ["main loop hser"]
GOTO Main_Loop
END
DISABLE INTERRUPT
INTERRUPT_HANDLER:
high portd.2
hserout ["Interrupt handler hser"]
PIR1.5 = 0 'Receive int clear
pause 1000
RESUME
ENABLE INTERRUPT
When i power up the pic, interrupt is active (portd.2 is a led) and will glow up. Sending serial data to usart wont make any difference.
Anybody who can help? or write a simple RX interrupt example?
Thanks in advance.;)
Archangel
- 3rd March 2010, 18:20
Hello,
first of all, im new on this forum and i'm from the Netherlands (spelling issue)
since a month, im programming PIC controllers for school. im using a big, pic16f877a device which have alot of functions, including interrupts.
However those interrupts dont work for me. I wrote a code, just to interrupt when serial data is incomming.
Heres the code:
;DEFINE HSER_RCSTA 90h (no function if baud rate is defined)
;DEFINE HSER_TXSTA 20h (no function if baud rate is defined)
define HSER_BAUD 9600
DEFINE HSER_SPBRG 25
define osc 20
Include "modedefs.bas"
ON INTERRUPT GOTO INTERRUPT_HANDLER
INTCON = %11000000
PIE1.5 = 1 ' enable interrupt on usart receive
Main_Loop:
low portd.2
pause 500
hserout ["main loop hser"]
GOTO Main_Loop
END
DISABLE INTERRUPT
INTERRUPT_HANDLER:
high portd.2
hserout ["Interrupt handler hser"]
PIR1.5 = 0 'Receive int clear
pause 1000
RESUME
ENABLE INTERRUPT
When i power up the pic, interrupt is active (portd.2 is a led) and will glow up. Sending serial data to usart wont make any difference.
Anybody who can help? or write a simple RX interrupt example?
Thanks in advance.;)
Hello, and welcome to the forum.
HSEROUT transmits HSERIN receives. That is where I would start . . . and understand , it must occur on the RX pin as defined in the Data Sheet. Additionally The hardware USART requires the RX port to "Idle High", which is to say, PULL UP Resistor required.
Arciure
- 4th March 2010, 09:51
ok, i added a 10k resistor from RX to Vdd. And you´re right its now interrupting :). however it doesnt return to the main program, and the serial data i receive is ""misformed" but it has the same sequence. I will try more things out now to make it work perfectly. Thx you
mackrackit
- 4th March 2010, 14:18
DISABLE INTERRUPT
ENABLE INTERRUPT
Should be
DISABLE
ENABLE
Charles Linquis
- 4th March 2010, 14:23
And I don't know your hardware - but. You can't run the output of a PC serial port directly into a hardware serial port of a PIC, even with a resistor. The PC output is LOW when no character is transmitted, while the PIC expects a HIGH when no character is transmitted. If you use a level-shifter/inverter like a MAX232 between your PIC and PC, you don't need a resistor (pull-up or otherwise), and the inversion will be taken care of for you.
Archangel
- 4th March 2010, 15:57
And I don't know your hardware - but. You can't run the output of a PC serial port directly into a hardware serial port of a PIC, even with a resistor. The PC output is LOW when no character is transmitted, while the PIC expects a HIGH when no character is transmitted. If you use a level-shifter/inverter like a MAX232 between your PIC and PC, you don't need a resistor (pull-up or otherwise), and the inversion will be taken care of for you.Or you could use a transistor to invert the P/C's inverted logic back to true. I first saw this method employed by P H Anderson in a serial LCD backpack I bought from him. Wulfden sells kits,based on his chips, and the schematic can be found here in his manual: http://www.wulfden.org/downloads/manuals/K107manual.pdf
If you go there be sure to visit his products page. He even sells the bare PCB if you don't want the kits.
http://www.wulfden.org/TheShoppe/products.shtml
Arciure
- 5th March 2010, 17:23
Serial data is transmitted wireless from my computer to the pic, using Xbee modules. The transmission is working fine, atleast the characters from the pic get correctly received. The PIC is interrupting, do some action, and resume back normally, when receiving something on UART. However i dont know yet if the incomming serial data is correct.
I put this code in the interrupt section
HSERIN [WAIT("*"),STR serdata\4]
hserout ["=",str serdata\4]
But it doesnt return anything. For example, i send the following sequence:
"*1234" it should return 1234. But it doesnt.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.