Problems with hwint1 on 20x2

I am using PE 5.5.1 trying to obtain communication btw a 20x2 (vs.c.0) based "box" and a pc/windows application. My idea is to use the axe027 cable btw the two, and use serrxd and sertxd on the picaxe side. The pc-application (written in ROBOTbasic) is to be the master, and send commands w/parameters to the picaxe, with pinb.0 (hwint1) hooked directly to the Serial In pin (icp2). Most of this works nicely, - except the interrupt part. I have tried hard to understand what the manual says about the interrupt system, but not much success. For example, what is the precise relationship btw. HintSetup and SetIntFlags?
I have searched the forum, I found this thread from 22-04-2012 "Need a good way to handle multiple interrupts". #4 by westaust55:

Code:
SETINTFLAGS OR %10100000,%10100000 ;  to set interrupt on background hardware serial receive or timer 0 overflow
do
loop

Interrupt:
IF ToFlag = 1 THEN
; do timer interrupt procvessing - or set/increment a flag for the main loop to continue processing
; let toflag = 0 ; to clear the flag if required
ELSE IF hserflag = 1 THEN
; do background receive processing - or set/increment a flag for the main loop to continue processing
; the value ‘hserptr -1’ indicates the last byte written, and ‘hserinflag = 1’ indicates a byte has been received
; let hserflah = 0 ; to clear the flag if required
ENDIF
RETURN
Even if this code is not dealing with hwint1, I guess it is relevant, because it deals with a hardware interrupt. So, I tried something similar with hwint1, but had to include 'HintSetup' in the setup part of the code, and 'SetIntFlags %0000010, %00000010' in the service routine.. Why? And bit 5 in the HintSetup seems to be in conflict with the Setintflags flags byte (bit1 =1. Or Did I misunderstand these bits?
Anyway, here is my attempt to have a hwint1 interrupt, triggered from the Serin In - pin, put together on a AXE091 board:
Code:
#picaxe 20X2     
#No_data 
#No_table
#terminal 19200				;bec	setfreq m16			 
	
setfreq m16				
IOinit:
	dirsB=%11111110			;b0,4  in. Rest OUT
	dirsC=%11111111			;No floating inputs to be sure..
	pinsC=$ff
Intrrptinit:					;Init HWint1
	HintSetup %00100010		;No intrrpt without it
	SetIntFlags %00000010, %00000010;No intrrpt without it
;*************************************************************************	
main:				 
goto main
;
;***********************************************************************

Interrupt:  		;triggered from pinb.0	fed by a (physically debounced) sw 
;							on the AXE091 board. Or from Serin In			 
	sertxd(#flags)					;Shows Hint1Flag and Hintflag set	
	toggle b.1						;To a LED, for recognisable action
	Hint1Flag=0						;if omitted continuous interrupts, that is understandable..
	SetIntFlags %00000010, %00000010       ;No intrrpt without this, either
Return
which works consistently running on an AXE091 board when I use an electronically debounced switch hooked up to pinb.0/hwint1. But as soon as I connect Serial In to the hwint1/b.0-pin, and send chars from the terminal in order to trigger hwint1, the interrupt only happen now and then. Why? (I've checked the signals with a scope .. seems ok) And, very surprising, rubbish is sent back to the pc/terminal immediately. (This is very bad for my application, It also, of course , appears on an oscilloscope) This rubbish is itself a mystery to me, how can THAT happen? (I know I can probably find a way around this, but I really want to understand what happens) .. I am really stuck ... any help is highly appreciated!!
 

hippy

Ex-Staff (retired)
If taking the download Serial In pin to the HINT1 pin you want a DISCONNECT command to stop the PICAXE from entering download mode when Serial In goes high.

If ultimately trying to receive every character via the HINT1 interrupt it won't work; the character will be part way through before any SERRXD in the interrupt routine can be started. You can however use the serial line going high as an indicator that data will be following and capture that.

It might be better to look at High-Speed Serial Background Receive; HSERSETUP.
 

Buzby

Senior Member
Hi rolfi,

I've not looked through your code yet, as I have a suggestion which gives you interrupt driven receive without using an extra pin.

The 20X2 has hardware UART which can automatically interrupt when characters are received. In fact, it is possible to get away without interrupts at all.

This is the way I would approach this task.

If you can change to using hserin and hserout I can give you some pointers.

Cheers,

Buzby
 

hippy

Ex-Staff (retired)
what is the precise relationship btw. HintSetup and SetIntFlags?
HINTSETUP defines the conditions which will cause the 'hintXflag' bits of the 'flags' variable to become set.

SETINTFLAGS defines which 'flags' bits becoming set will cause the interrupt routine to be entered.

Your second example code is correct for entering the interrupt routine when HINT1 pin goes high.
 
Oh, wow, stupid, stupid me!!! I forgot the 'disconnect' , that explains the failure... Thanks a lot!! I did not intend to do serrxd on the fly, just "wake UP" the 20X2 from whatever it might be doing, and then send an acknowledge msg to the pc, which, in turn, should send command and parameters...
 
Top