SERIN Interrupt

erco

Senior Member
Can an interrupt happen on an 08M2 while it's waiting for data from a SERIN command with no timeout?
 

hippy

Technical Support
Staff member
No, is the simple answer.

Interrupts are only polled and the 'Interrupt:' routine jumped to between commands or within the PAUSE command - Effectively the interrupt prematurely terminates the PAUSE, then it's between commands and the interrupt happens.

That also applies to the HINTx hardware interrupts; the flag to interrupt on will get set while SERIN is waiting but won't be acted upon until it completes.
 

PhilHornby

Senior Member
I realise this is an old thread, but it's pertinent to something I was investigating ...
Can an interrupt happen on an 08M2 while it's waiting for data from a SERIN command with no timeout?
Not only does the interrupt 'not happen' during the SERIN, the presence of the event goes completely undetected - the interrupt is not triggered after the SERIN completes :(

By contrast, the Interrupt-on-Change flags, do still work (y). (See for example PIC12(L)F1840 datasheet, Section 13.0)

The following code demonstrates this. Even though the SERIN uses a timeout, the Interrupt rarely triggers (if you repeatedly invoke it, you can sometimes catch it at a point in the loop, where the SERIN isn't active). The Interrupt-on-Change flag does get set (even if the interrupt happens to trigger).

Rich (BB code):
#picaxe 08m2
;
; SFRs
; 
;To convert to Picaxe equivalent, we do the following:-
;
;  3    9    1          Example 'RAW PIC' value
;0011 1001 0001
;xx|  |xx| ||||   
;  \  / /  |||| 
;   | | |  ||||
;   v v v  vvvv
;  11 1 1  0001
;    F      1           Translated Picaxe value
;

;Interrupt On Change SFRs

Symbol IOCAP            = $F1                   ;$391 - Capture positive edges
Symbol IOCAN            = $F2                   ;$392 - Capture negative edges
Symbol IOCAF            = $F3                   ;$393 - Capture flag
;
;     START PROGRAM
;
      Pullup  %00010010                         ;Pullup C.4 (switch to gnd) and C.1 (serin)
      
      gosub EnableInterrupts                    ;like it says. Interrupt when switch pressed.

      PokeSfr IOCAN,%00010000                   ;capture negative-going transitions on C.4
      PokeSfr IOCAF,0                           ;say none captured so far
do
;
;     Main loop. 
;
      sertxd ("R")
      serin 5000,TimeOut,C.1, T4800_4,b0      ;read a single byte into b0 with 5 second timeout
      sertxd ("C")                              ;Read a character via SERIN
      goto skip
Timeout:
      sertxd ("T")
skip:
      PeekSfr IOCAF, b1                         ;get pin no.s that have edge detections
      if b1 <> 0 then
            ;
            ; -ve going edge detection (can only be C.4 - not enabled for other pins)
            ;
            sertxd(cr,lf,"EDGE",cr,lf)
            PokeSfr IOCAF, 0                    ;reset Switch detections
      endif
loop


Interrupt:
;
;     C.4 has gone LOW - switch pressed
;
      sertxd (cr,lf,"INTERRUPT!",cr,lf)
;
;     Re-enable interrupt for next time
;
EnableInterrupts:
      do : loop while PinC.4 = 0                ;;;Wait for Switch to be released
      setint %00000000,%00010000                ;;;(re)enable interrupt on PinC.4 LOW
      return
 
Last edited:

inglewoodpete

Senior Member
SerIn is implemented with "bit banging". In order to achieve this, strict timing for the accurate capture of each bit is required. This results in everything else being ignored during SerIn (or SerOut or SerTxd).

Interrupt-on-change (X2 chips only) is a hardware capturing/latching function of the PICAXE's underlying silicon, so can record a pin's transition for later processing.
 

hippy

Technical Support
Staff member
By contrast, the Interrupt-on-Change flags, do still work
Yes, some of those are what are used by the HINTx flags and interrupts.

The 'changed' flags will be set in hardware whilst the SERIN is executing and remain set when it completes or timesout. At that point they can be read or an interrupt will then happen.
 
Top