HINTSETUP manual error?

MartinM57

Moderator
I'm not having a good day with manual 2 :(

It says...HINTSETUP mask
- mask is a variable/constant which defines which interrupt pins to activate.
Bit 7 - reserved
Bit 6 - Interrupt 2 Trigger (0 = rising edge, 1 = falling edge)
Bit 5 - Interrupt 1 Trigger (0 = rising edge, 1 = falling edge)
Bit 4 - Interrupt 0 Trigger (0 = rising edge, 1 = falling edge)
Bit 3 - reserved
Bit 2 - Interrupt 2 Enable
Bit 1 - Interrupt 1 Enable
Bit 0 - Interrupt 0 Enable (not 20X2)

I'm pretty convinced that the 'triggers' are the wrong way round (and also re-inforced by BB on http://www.picaxeforum.co.uk/showpost.php?p=102100&postcount=6) although not noted as a manual error

I've got some code that has a normally high signal on B.0 (hint0) and I want an interrupt when it transitions low (and it stays low until I reset it - yet to do)

With HINTSETUP %00010001 nothing happens, but with HINTSETUP %00000001 is works fine. Here's an extract of the output ... and the code follows

Code:
started...
In main, pinsB = 1 hint0flag = 0
In main, pinsB = 1 hint0flag = 0
In interrupt, pinsB = 0 hint0flag = 1
In main, pinsB = 0 hint0flag = 0
In main, pinsB = 0 hint0flag = 0
Code:
#picaxe 28x2
#no_table

setfreq em32

hintsetup %00000001 ;hint0 (pin B.0 - leg 21) trigger = falling edge and hint0 enabled
                              ;but manual says it should be hintsetup %00010001
setintflags %00000001,%00000001 ; interrupt on INT0

pause 1000 ;wait for F8 terminal window
sertxd ("started...", CR, LF)

main:
	b0 = pinsB
	sertxd ("In main, pinsB = ", #b0, " hint0flag = ", #hint0flag, CR, LF)
	pause 4000
goto main

interrupt:
	b0 = pinsB
	sertxd ("In interrupt, pinsB = ", #b0, " hint0flag = ", #hint0flag, CR, LF)
	hint0flag=0 ;clear the hint0 interrupt flag
	setintflags %00000001,%00000001 ;reset intflags to interrupt on INT0
return
 

hippy

Ex-Staff (retired)
You are right, %00000001 trigers on falling edge, %000100001 triggers on rising edge. I linked C.0 output into B.0 input so there were no button bounce issues, then delayed and raised C.0 later on.

#Picaxe 28X2
#Terminal 9600

Low C.0
Pause 2000

HIntSetup %00010001
SetIntFlags %00000001, %00000001
For b0 = 1 To 10
SerTxd( "LOW " )
Pause 1000
Next
High C.0
Do : Loop

Interrupt:
SerTxd( "HIGH", CR, LF)
End


Is it a manual error or a firmware implementation error opposite to intended ? If it works the same on all X2's we'll probably change the manual description. The simulator works as per the manual description at present so that's likely to follow suit.

Sorry about that, but thanks for pointing it out.
 

MartinM57

Moderator
...and maybe another one? Or at least an inconsistency?

Are hserflag and hserinflag the same thing - if not, I can't see the subtle difference/don't know which one to use (as in the thing I need to clear down to 0 in the interrupt service routine when a background hserin is received)

I see that hserinflag is an additional reserved in Appendix 1 of Manual 2, but not hserflag...

Suffice to say, I'm having problems with my background receive - the external device is sending 5 bytes but I'm only picking up 2 of them :(
 

hippy

Ex-Staff (retired)
The compiler accepts both 'hserflag' and 'hserinflag' and they seem to be synonyms for the same flag from my testing.

You may have to use fancy footwork to use background receive and interrupts in some cases, especially where multiple data is arriving at high-speed. You're going to have to describe the nature of what's being received and show the code for handling it for a better answer I'm afraid.
 

MartinM57

Moderator
OK here goes....I've simplified the problem right down to background hserin receive (no interrupts)

I have three example multi-byte commands to send to the device and it sends back respectively:
- a 6 byte response
- a 4 bytre response
- a 1 byte response

The code isn't complex but has three sections, one for each command.
Code:
#picaxe 28x2
setfreq m8

;9600 baud, background receive hserin serial data to the scratchpad
hsersetup B9600_8, %001

pause 1000
sertxd ("Started...and pausing for 5 seconds", CR, LF)
pause 5000

;send command 1 to device
hserout 0,($12,$01,$49,$5C)
sertxd ("Command 1 sent...", CR, LF)

;wait for response (is "instantaneous" anyway)
pause 2000

;print scratchpad - should be 6 bytes ... $06 $12 $02 $00 $FF $1A
b1 = hserptr - 1
for b0 = 0 to b1
	get b0, b2
	sertxd ("sp[", #b0, "]=", #b2, CR, LF)
next

hserptr = 0

;send command 2 to device
hserout 0,($12,$01,$53,$66)
sertxd ("Command 2 sent...", CR, LF)

;wait for response (is "instantaneous" anyway)
pause 2000

;print scratchpad - should be 4 bytes ... $06 $11 $00 $11
b1 = hserptr - 1
for b0 = 0 to b1
	get b0, b2
	sertxd ("sp[", #b0, "]=", #b2, CR, LF)
next

hserptr = 0

;send command 3 to device
hserout 0,($11,$0E,$1B,$44,$4C,$1B,$47,$44,$00,$00,$00,$00,$DF,$01,$0F,$01,$60)
sertxd ("Command 3 sent...", CR, LF)

;wait for response (is "instantaneous" anyway)
pause 2000

;print scratchpad - should be 1 byte ... $06
b1 = hserptr - 1
for b0 = 0 to b1
	get b0, b2
	sertxd ("sp[", #b0, "]=", #b2, CR, LF)
next

end
The terminal output shows:
- the first two bytes of command 1 correct, but last 4 bytes missing
- the first two bytes of command 2 correct, but last 2 bytes missing
- the single byte of command 3 correct
Code:
Started...and pausing for 5 seconds
Command 1 sent...
sp[0]=6
sp[1]=18
Command 2 sent...
sp[0]=6
sp[1]=17
Command 3 sent...
sp[0]=6
I can't say it's NOT a hardware problem as I can't monitor/record the hserin line, but sending the same commands to the device via Brays Terminal produces perfect responses.
 

hippy

Ex-Staff (retired)
Can't coment on what may be wrong but I setup an 08M churning data out to a 28X2 and had no problems ...

#Picaxe 08M
SetFreq M8
Do
Pause 10000
SerTxd( $06, $12, $02, $00, $FF, $1A )
Loop

#Picaxe 28x2
#Terminal 9600
SetFreq m8
HSerSetup B9600_8, %111
Do
hserptr = 0
Do : Loop While hserptr = 0 ' Wait until some data rxd
Pause 2000 ' Wait 2 seconds for all data
b1 = hserptr - 1
For b2 = 0 To b1
Get b2, b3
SerTxd ( "sp[", #b2, "]=$" )
b0 = b3 / 16 + "0" : If b0 > "9" Then : b0=b0+7 : End If
SerTxd( b0 )
b0 = b3 & 15 + "0" : If b0 > "9" Then : b0=b0+7 : End If
SerTxd( b0, CR, LF )
Next
SerTxd( CR, LF )
Loop

Repeatable results ...

sp[0]=$06
sp[1]=$12
sp[2]=$02
sp[3]=$00
sp[4]=$FF
sp[5]=$1A
 
Top