PDA

View Full Version : A little DT_INT confusion.



circuitpro
- 19th October 2010, 03:36
I'm still a little new to DT_INTs, and am having a little trouble. I'm trying to use two interrupts, one on a hardware UART, and the second using Ext Int 2. The hardware uart is reading an RFID tag and goes on to just send the data out the debug port.

Ext Int 2 is simply a wire that, when grounded, should write some fake RFID data to my TAG string, and send that out the debug port as well.

If the External interrupt goes first, it works ONCE; but after the UART interrupt works, the data that was put in the data string is only transmitted AFTER the next data read by the uart!!

I am at a loss to understand what's happening here. Can somebody see my goof/s?


'INCLUDE FILES FOR DT INTERRUPTS
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"

'======================
'CONSTANTS
'======================
MODE CON 6 'SERIN2/SEROUT2 TO USE 38400 BAUD

'======================
'VARIABLES
'======================
TP1 VAR PORTA.0 'TP1 (GC SIDE)
TP2 VAR PORTA.1 'TP2 (GC SIDE)
TP3 VAR PORTA.2 'TP3 (READER SIDE)
LED VAR PORTA.3 'ACTIVITY LED
ITP0 VAR PORTA.5 'INTERNAL TEST POINT 0
DAV VAR PORTA.6 'DAV (INT) FLAG TO GC
DATA0 VAR PORTB.0 'WIEGAND INPUT
DATA1 VAR PORTB.1 'WIEGAND INPUT
EXTINT VAR PORTB.2 'TERMINAL STRIP INTERRUPT
LEDR VAR PORTB.3 'RED LED
LEDG VAR PORTB.4 'GRN LED
BUZZ VAR PORTB.5 'BUZZER
ITP1 VAR PORTC.0 'INTERNAL TEST POINT 1
ITP2 VAR PORTC.1 'INTERNAL TEST POINT 2
DIAGIN VAR PORTC.2 'DIAG IN (DEBUGIN)
DIAGOUT VAR PORTC.3 'DIAG OUT (DEBUG)

X VAR BYTE
Y VAR BYTE
Z VAR BYTE
TAG VAR BYTE[10]

CLEAR

'INITIALIZE INTERRUPTS
ASM
INT_LIST MACRO ;IntSource,Label,Type,ResetFlag?
INT_Handler INT2_INT, _EXTTS,PBP,yes
INT_Handler RX_INT, _RDRINT,PBP,yes
ENDM
INT_CREATE ;CREATES THE INTERRUPT PROCESSOR
ENDASM

'ENABLE INTERRUPTS
@ INT_ENABLE RX_INT ;READER UART INTERRUPT
@ INT_ENABLE INT2_INT ;EXTERNAL INTERRUPT

'======================
MAIN:
'======================
PAUSE 1
GOTO MAIN

'======================
RDRINT: 'TAG READER INTERRUPT!
'======================
HSERIN [WAIT($02),STR TAG\8\$03] 'READ ENTIRE TAG
GOSUB SHOW 'SEND TAG/KEYPAD DATA TO DIAG PORT
GOSUB ERASETAG
@ INT_RETURN

'======================
EXTTS:
'======================
'WRITE TAG DATA HERE:
'00995031
TAG[0]=$30:TAG[1]=$30:TAG[2]=$39:TAG[3]=$39:TAG[4]=$35:TAG[5]=$30:TAG[6]=$33:TAG[7]=$31
GOSUB SHOW
GOSUB ERASETAG
@ INT_RETURN

'======================
SHOW:
'======================
'SHOW TAG CHARACTERS:
SEROUT2 DIAGOUT,MODE,[STR TAG,10,13] 'SEND DATA TO DIAG PORT
RETURN

ERASETAG: 'ERASE DATA
FOR Z=0 TO 10
TAG[Z]=$00
NEXT Z
RETURN

mackrackit
- 19th October 2010, 06:08
A couple of things that might be causing the trouble.

You have TAG defined as ten elements but you erase 11
FOR Z=0 TO 10

Try removing the WAIT in the HSERIN statement. Triggers once then it has to WAIT for the second time data is sent to move on....

And I do not see where the USART is set up?

You may want to read over this
http://www.picbasic.co.uk/forum/showthread.php?t=3251&p=23530#post23530

circuitpro
- 19th October 2010, 14:23
I will fix the TAG error as soon as I get to work, and check on the WAIT also. Either interrupt works fine by itself, but not both together. I'll let you know if the WAIT fixed anything. The serial port is set up ok, I just thought the code was getting kind of long to post. Thanks for the reply!

circuitpro
- 19th October 2010, 20:06
I simplified things somewhat to try to isolate my error, but I'm not finding it.

After the UART interrupt is used, the INT2 interrupt will not send it's data until AFTER the NEXT uart interrupt!! I'm lost.


'======================
'PORT SETUPS
'======================
ASM
;PORT A
CLRF PORTA
MOVLW 07h
MOVWF ADCON1 ;A/D'S OFF
MOVWF 07h
MOVWF CMCON ;COMPARATORS OFF
MOVLW 00000000b ;PIN DIRECTION PORT A
MOVWF TRISA

;PORT B
CLRF PORTB
MOVLW 0Fh
MOVWF ADCON1 ;A/D'S OFF
MOVLW 11000111b ;PIN DIRECTION PORT B
MOVWF TRISB

;PORT C
CLRF PORTC
MOVLW 10011000b ;PIN DIRECTION PORT C
MOVWF TRISC
ENDASM

'======================
'SET REGISTERS
'======================
INTCON2.7=0 'PORT B PULLUPS ON (0=ON)
INTCON2.6=0 'INT0 TRIGGERS ON FALLING EDGE
INTCON2.5=0 'INT1 TRIGGERS ON FALLING EDGE
INTCON2.4=0 'INT2 TRIGGERS ON FALLING EDGE

'======================
'DEFINES
'======================
DEFINE OSC 20

DEFINE HSER_RCSTA 90h 'Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h 'Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 'Clear overflow automatically
DEFINE HSER_SPBRG 8 '9600 Baud @ 20MHz, -0.03%
SPBRGH = 2
BAUDCON.3 = 1 'Enable 16 bit baudrate generator

'DEBUG PORT (Group Controller)
DEFINE DEBUG_REG PORTC 'DEBUG PIN IS IN PORT C
DEFINE DEBUGIN_REG PORTC 'DEBUGIN PIN IS IN PORT C
DEFINE DEBUG_BIT 5 'DEBUG TRANSMIT PORT C5
DEFINE DEBUGIN_BIT 4 'DEBUG RECEIVE PORT C4
DEFINE DEBUG_BAUD 57600 '57600 BAUD TO GC
DEFINE DEBUG_MODE 0 'INVERTED OUTPUT (COMPENSATE FOR MAX232)

'INCLUDE FILES FOR DT INTERRUPTS
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"

'======================
'CONSTANTS
'======================
MODE CON 6 'SERIN2/SEROUT2 TO USE 38400 BAUD

'======================
'VARIABLES
'======================
TP1 VAR PORTA.0 'TP1 (GC SIDE)
TP2 VAR PORTA.1 'TP2 (GC SIDE)
TP3 VAR PORTA.2 'TP3 (READER SIDE)
LED VAR PORTA.3 'ACTIVITY LED
ITP0 VAR PORTA.5 'INTERNAL TEST POINT 0
DAV VAR PORTA.6 'DAV (INT) FLAG TO GC
DATA0 VAR PORTB.0 'WIEGAND INPUT
DATA1 VAR PORTB.1 'WIEGAND INPUT
EXTINT VAR PORTB.2 'TERMINAL STRIP INTERRUPT
LEDR VAR PORTB.3 'RED LED
LEDG VAR PORTB.4 'GRN LED
BUZZ VAR PORTB.5 'BUZZER
ITP1 VAR PORTC.0 'INTERNAL TEST POINT 1
ITP2 VAR PORTC.1 'INTERNAL TEST POINT 2
DIAGIN VAR PORTC.2 'DIAG IN
DIAGOUT VAR PORTC.3 'DIAG OUT
FLAG VAR BIT

X VAR BYTE
Y VAR BYTE
Z VAR BYTE
TAG VAR BYTE[11]

CLEAR

'INITIALIZE INTERRUPTS
ASM
INT_LIST MACRO ;IntSource,Label,Type,ResetFlag?
INT_Handler RX_INT, _RDRINT,PBP,yes
INT_Handler INT2_INT, _EXTTS,PBP,yes
ENDM
INT_CREATE ;CREATES THE INTERRUPT PROCESSOR
ENDASM

'ENABLE INTERRUPTS
@ INT_ENABLE RX_INT ;UART INTERRUPT
@ INT_ENABLE INT2_INT ;EXT INT 2

'======================
MAIN:
'======================
FOR X=1 TO 1000
PAUSEUS 100
NEXT X
GOTO MAIN

'======================
RDRINT: 'TAG READER INTERRUPT!
'======================
HSERIN [STR TAG\9\$03]
SEROUT2 DIAGOUT,MODE,[STR TAG,10,13] 'SEND DATA TO DIAG PORT
FOR Z=0 TO 10
TAG[Z]=$00
NEXT Z
@ INT_RETURN

'======================
EXTTS:
'======================
SEROUT2 DIAGOUT,MODE,["00995031",10,13]
@ INT_RETURN

mackrackit
- 20th October 2010, 00:18
I am not sure where the problem is either.
Maybe it has something to do with setting the interrupt registers before the instants are enabled. Darrel.s routine sets these so you do not need to do it.

Reading through other post this seems similar (post 52 and 53). I am sure you have read them but it is all I can find at the moment.
http://www.picbasic.co.uk/forum/showthread.php?t=3251&p=23402#post23402

And I think this is related
http://www.picbasic.co.uk/forum/showthread.php?t=1944&p=9786#post9786

Did you say what PIC you are using?

circuitpro
- 20th October 2010, 00:29
It's a PIC18F2520.

I was going to run the risk of talking to myself, and add another short bit - I finally got smart, and put something in the main loop, so I could see if the uart interrupt handler ever returned from it's job, and found that it isn't!!

Everything just appears to stop after a uart interrupt. It does what it's suppose to, (reads from one port, and writes to the other) and never returns to the main loop.

I'm at a loss, and hoping that would be of some help.


'INITIALIZE INTERRUPTS
ASM
INT_LIST MACRO ;IntSource,Label,Type,ResetFlag?
INT_Handler INT2_INT, _EXTTS,PBP,yes
INT_Handler RX_INT, _RDRINT,PBP,yes
ENDM
INT_CREATE ;CREATES THE INTERRUPT PROCESSOR
ENDASM

START:
GOSUB CLS
PAUSE 100
SEROUT2 DIAGOUT,MODE,["SDIF2 VER. 1",10,13]

'ENABLE INTERRUPTS
@ INT_ENABLE RX_INT ;READER UART INTERRUPT
@ INT_ENABLE INT2_INT ;EXTERNAL INTERRUPT

'======================
MAIN:
'======================
SEROUT2 DIAGOUT,MODE,["."]
FOR X=1 TO 100
PAUSE 1
NEXT X
GOTO MAIN

'======================
RDRINT: 'TAG READER INTERRUPT!
'======================
HSERIN [WAIT($02),STR TAG\8\$03] 'READ TAG FROM THIS PORT (WORKS)
SEROUT2 DIAGOUT,MODE,[STR TAG,10,13] 'SEND TAG DATA TO THIS PORT (WORKS)
@ INT_RETURN ; <=== THIS IS NOT RETURNING! (DOES NOT WORK)

''======================
EXTTS:
''======================
'SEND SPECIAL DATA NOW
SEROUT2 DIAGOUT,MODE,["00995031",10,13] '(WORKS)
@ INT_RETURN ;(WORKS)

circuitpro
- 20th October 2010, 00:46
:) Dave! You nailed it. I don't know how you remember/find all these links!!

I changed the Uart interrupt to this, and it now works:


'======================
RDRINT: 'TAG READER INTERRUPT!
'======================
HSERIN [WAIT($02),STR TAG\8\$03] 'READ TAG FROM THIS PORT (WORKS)
SEROUT2 DIAGOUT,MODE,[STR TAG,10,13] 'SEND TAG DATA TO THIS PORT (WORKS)
While PIR1.5 = 1 ; clear the buffer
HSERIN [X]
Wend
@ INT_RETURN ; <=== NOW WORKING :-)

I want to really look up what that is doing now, and write a note or two. THANK YOU.

Len