My latest headache which I have simplified right down to show the problem
Hardware is an SPI device connected to HSPI SDO(MOSI), SDI(MISO) and SCK(CLK), with its Slave Select on pin B.7, plus a DS1307 SQW output at 1Hz attached in the HINT1 pin
The following code sends data to an SPI device (nice and slowly at m4) and reads the return code - it runs fine for hours on end...note that interrupts are disabled
If I uncomment the three lines that set up the HINT1 interrupt, so that I get a 1Hz interrupt that does nothing except re-enable the interrupt for next time, the code runs for between 1 and 10 seconds (seemingly randomly) before locking the PICAXE up completely - no more HSPI commands are sent and a new download can only be made after a hard reset.
If i put some sertxds into the main loop to see what's going on, with HINT1 enabled, it runs perfectly. but very slowly of course e.g.
It seems that hardware interrupting whilst using hardware SPI at a reasonably fast rate has a nasty interaction...thoughts?
Hardware is an SPI device connected to HSPI SDO(MOSI), SDI(MISO) and SCK(CLK), with its Slave Select on pin B.7, plus a DS1307 SQW output at 1Hz attached in the HINT1 pin
The following code sends data to an SPI device (nice and slowly at m4) and reads the return code - it runs fine for hours on end...note that interrupts are disabled
Code:
#picaxe 28x2
#no_table
#slot 0
#terminal 4800
symbol hint_setting = b36
'deselect SPI slave
high B.7
setfreq m4
'stabilise
pause 500
sertxd ("started...", CR, LF)
'setup hspi
hspisetup spimode00, spislow
'set up interrupt on falling edge of hint1 - note COMMENTED OUT FOR SUCCESS
'hint_setting = %00000010
'hintsetup hint_setting
'setintflags %00000010,%00000010 ' enable hint1
main:
'select SPI slave
low B.7
'send data
hspiout ($11,$05,$1B,$5A,$54,$30,$00,$0F)
'get response
hspiin (b0)
'deselect SPI slave
high B.7
goto main
interrupt:
hint1flag = 0
return
If i put some sertxds into the main loop to see what's going on, with HINT1 enabled, it runs perfectly. but very slowly of course e.g.
Code:
main:
'select SPI slave
sertxd("low B.7", CR, LF)
low B.7
'send data
sertxd("hspiout ($11,$05,$1B,$5A,$54,$30,$00,$0F)", CR, LF)
hspiout ($11,$05,$1B,$5A,$54,$30,$00,$0F)
'get response
sertxd("hspiin (b0)", CR, LF)
hspiin (b0)
'deselect SPI slave
sertxd("high B.7", CR, LF)
high B.7
sertxd("goto main", CR, LF)
goto main