Parallel Tasking with serin command not working

hookset

New Member
Parallel tasking between Start0 and Start1 is fine until the serin command is hit in "Start0" at that point Start1 also stops. I have attached a snip-it of my code below. To test my theory I added a Do statement (not included in the code below) at the being of my Start1 that would blink ledpir. the led would blink several times then just stay high. So I ran the code in the simulation software, where it appears that both Start0 and Start1 halt execution when Start0 hits the "serin" command. Of course Start0 should halt while waiting to receive a signal.

So will serin work with parallel tasking?

Thanks..
Edited - this all started when I could only get my code to receive RF signal "Start0". Start1 - a switch at this point, would not execute. both Start0 and Start1 run fine as a single application.

Code:
 #picaxe 18m2 ;;
#Terminal 4800


symbol sw1 = pinC.1 ' Switch 1
symbol sw2 = pinC.0 ' Switch 2
symbol sw3 = pinC.7 ' Switch 3
symbol sw4 = pinC.6 ' Switch 4

symbol PIR = pinB.1 ; define pin C.1 as PIR input
symbol RF  = pinB.2 ; define IR in pin
symbol LDR = pinB.3 ; define LDR pin

symbol light = B.4 ; define pin B.1 with the name "light"
symbol rec   = B.5 ; define pin B.2 with the name "video"
symbol power = B.6 ; define pin B.3 with the name "power"
symbol ledpir= B.7 ; define pin B.0 with name "ledpir" LED to show detection


Start0: 

warmup:
low ledpir  

;========== turn on LED to indicate warm-up mode =========='

for w5 = 1 to 5
  high ledpir
  pause 500
  low ledpir
  pause 500
next w5

;------------------------Look for detection ------------------------------------;

Do
	pause 3000
	serin B.2, T4800, ( "XYZZY" ), b0, b1, b2, b3, b4, b5, b6, b7 
		;debug  ; Show the data received 
   suspend 1
      gosub day   	; Check for day / night
	gosub power_on
	gosub rec_on
	gosub light_on
	pause 30000 	; Record for 30 sec's
	gosub rec_off
	gosub light_off
	gosub power_off

	pause 10000 	; pause 10 sec - delay 
	resume 1   
loop
   
;==========  PIR Section ==========

Start2:
	If PIR > 0 then 
	suspend 0
      gosub day   	; Check for day / night
	gosub power_on
	gosub rec_on
	gosub light_on
	pause 30000 	; Record for 30 sec's
	gosub rec_off
	gosub light_off
	gosub power_off

	pause 10000 	; pause 10 sec - delay 
	resume 0  	
   
 Else
      pause 200
  
 endif
 
 goto Start2
 

Goeytex

Senior Member
The Picaxe does not do true parallel processing as it can only execute one command at a time. It only really simulates parallel processing by cleverly switching back and forth between tasks. So any blocking command will halt BOTH tasks until it completes.

Serin is a blocking command so ALL command processing will halt until serin is done.
 

hookset

New Member
Thanks guys.
Now that you said that - I remember reading that. Wish I could chalk it up to the mountain cedar that has my head clogged - but no I am just still a :confused: newbie
 

westaust55

Moderator
Depending upon where you incoming data is coming from you can try to send a pulse or some extra characters first and either scan or use interrupts to detect the initial pulse or pre data.
When a pulse is found then branch to code with the SERIN command.
 

Goeytex

Senior Member
While the use of hserin may seem a good option in addressing the tasking issue, on M2 parts the limitations presented by the tiny little two byte receive buffer opens up a new can of worms as how to process the incoming data in a timely & effective manner.

The original code shows receiving 8 back to back bytes with a 5 byte qualifier, which is beyond the capability of M2 hserin and its little 2 byte receive buffer.

Adjustments would need to be made on the other side to send no more than 2 bytes at a time and then pausing several milliseconds to allow the 18m2 code to process the bytes before sending the next two bytes.
 

hippy

Ex-Staff (retired)
It is true that a sender may need modifying to give the receiver time to execute but that could be quite easy to do if put into a routine which sends the data ...

Code:
[color=Black]TransmitData:
  [/color][color=Blue]For [/color][color=Purple]b8 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]To [/color][color=Navy]12
    [/color][color=Blue]LookUp [/color][color=Purple]b8[/color][color=Black], [/color][color=Blue]( [/color][color=Red]"XYZZY"[/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7 [/color][color=Blue])[/color][color=Black], [/color][color=Purple]b9
    [/color][color=Blue]SerOut B.7[/color][color=Black], [/color][color=Blue]N2400[/color][color=Black], [/color][color=Blue]( [/color][color=Purple]b9 [/color][color=Blue])
    Pause [/color][color=Navy]10 
  [/color][color=Blue]Next
  Return[/color]
On the receiving side; processing the data should not be too hard ...

Added: See posts #11 and #12 for corrections to this code

Code:
[color=Navy]#Picaxe [/color][color=Black]18M2[/color]

[color=Blue]Start0:
  HserSetup B2400_4[/color][color=Black], [/color][color=Navy]%000
  [/color][color=Blue]Do
    Do
      Do
        Do
          Do
            Do
              Gosub [/color][color=Black]GetChar
            [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Red]"X"
            [/color][color=Blue]Gosub [/color][color=Black]GetChar
          [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Red]"Y"
          [/color][color=Blue]Gosub [/color][color=Black]GetChar
        [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Red]"Z"
        [/color][color=Blue]Gosub [/color][color=Black]GetChar
      [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Red]"Z"
      [/color][color=Blue]Gosub [/color][color=Black]GetChar
    [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Red]"Y"
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b2 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b3 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b4 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b5 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b6 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b7 [/color][color=DarkCyan]= [/color][color=Purple]w7
    [/color][color=Blue]SerTxd( [/color][color=Red]"Received="[/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black], [/color][color=Blue]CR[/color][color=Black], [/color][color=Blue]LF )
  Loop
  [/color]
[color=Black]GetChar:
  [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Navy]$FFFF
  [/color][color=Blue]Do
    HSerIn [/color][color=Purple]w7
  [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]<= [/color][color=Navy]$FF
  [/color][color=Blue]Return
  
Start1:
  Do
    Toggle B.7
    Pause [/color][color=Navy]500
  [/color][color=Blue]Loop[/color]
Alternatively one can move the receive packet handling into a separate PICAXE and poll for when a data packet is received and available or use an NKM2401 when receiving RF data.

Trying to do everything on one chip for minimal cost or hardware simplicity can mean trade-offs.
 
Last edited:

Goeytex

Senior Member
Not too hard ? Are you kidding? I'd like to see a newbie or even most experienced Picaxe users come up with a similar receive side solution with M2 hserin.

In the demo receive code above, what happens if one qualifier byte is received correctly and the next one is wrong or corrupted? I might be wrong, but at a glance, it looks to me like the loop will hang. I think some additional code would need to be included to jump out of the loop(s) after a certain time if there is an error. By the time the code is worked out and debugged, it might look like an unintelligible mess to all but the initiated. Not that it won't work, but the code sample clearly demonstrates the hoops that must be jumped through to use M2 hserin for serial comm.
 

hippy

Ex-Staff (retired)
Actually you are right; that's not the right algorithm for catching the qualifiers. That's what comes from quickly knocking code up during lunch time and thanks for spotting that. A better algorithm may be somewhat simpler and that could be made better still with some additional time spent on that -

Code:
[color=Black]GetQualifier:
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"X" [/color][color=Blue]Then [/color][color=Black]GetQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Y" [/color][color=Blue]Then [/color][color=Black]GetQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Z" [/color][color=Blue]Then [/color][color=Black]GetQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Z" [/color][color=Blue]Then [/color][color=Black]GetQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Y" [/color][color=Blue]Then [/color][color=Black]GetQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Purple]w7[/color]
  etc
Agreed; there are some hoops to jump through but challenging problems don't always have a simple solution.

I would however say it's not that overly complicated. I would probably restructure the earlier code as below. Still untested ...

Code:
[color=Navy]#Picaxe [/color][color=Black]18M2[/color]

[color=Blue]Start0:
  HserSetup B2400_4[/color][color=Black], [/color][color=Navy]%000
  [/color][color=Blue]Do
    Gosub [/color][color=Black]GetPacket
    [/color][color=Blue]SerTxd( [/color][color=Red]"Received="[/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7[/color][color=Black], [/color][color=Blue]CR[/color][color=Black], [/color][color=Blue]LF )
  Loop
   
Start1:
  Do
    Toggle B.7
    Pause [/color][color=Navy]500
  [/color][color=Blue]Loop[/color]

[color=Black]GetPacket:
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"X" [/color][color=Blue]Then [/color][color=Black]GetPacket
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Y" [/color][color=Blue]Then [/color][color=Black]GetPacket
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Z" [/color][color=Blue]Then [/color][color=Black]GetPacket
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Z" [/color][color=Blue]Then [/color][color=Black]GetPacket
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Y" [/color][color=Blue]Then [/color][color=Black]GetPacket
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b2 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b3 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b4 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b5 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b6 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b7 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Return
 [/color]
[color=Black]GetChar:
  [/color][color=Purple]w7 [/color][color=DarkCyan]= [/color][color=Navy]$FFFF
  [/color][color=Blue]Do
    HSerIn [/color][color=Purple]w7
  [/color][color=Blue]Loop Until [/color][color=Purple]w7 [/color][color=DarkCyan]<= [/color][color=Navy]$FF
  [/color][color=Blue]Return[/color]
 
Last edited:

hippy

Ex-Staff (retired)
I think this is what it should be to manually match each character received to do it how a SERIN would ...

Code:
[color=Black]GetQualifier:
  [/color][color=Blue]Gosub [/color][color=Black]GetChar
CheckIfFirstQualifier: 
  [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"X" [/color][color=Blue]Then [/color][color=Black]GetQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Y" [/color][color=Blue]Then [/color][color=Black]CheckIfFirstQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Z" [/color][color=Blue]Then [/color][color=Black]CheckIfFirstQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Z" [/color][color=Blue]Then [/color][color=Black]CheckIfFirstQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Blue]If [/color][color=Purple]w7 [/color][color=DarkCyan]<> [/color][color=Red]"Y" [/color][color=Blue]Then [/color][color=Black]CheckIfFirstQualifier
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Purple]w7
  [/color][color=Blue]Gosub [/color][color=Black]GetChar : [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Purple]w7[/color]
  etc
This should catch "XYXYZZYabcdefgh" and similar.
 

Goeytex

Senior Member
Below is another way. It uses hippy's code for sending data with space between bytes. However it uses an interrupt and serin instead of hserin. Tested on the bench with a 14M2 it works well at 2400 baud. However, parallel tasking forces the processor clock to be 4Mhz, meaning the setfreq command cannot be used to increase the processor speed to reduce processing overhead and improve serin performance. For all practical purposes this means that the baud rate cannot be increased above 2400 due to the processing overhead requirements of serin. Personally I would abandon parallel processing due to the many constraints and slow performance and just use normal code with the processor operating at 16 or 32 MHz. But here it is anyway with parallel tasking.


Transmit Code

Code:
[color=Black]Transmit_Data:[/color]
[color=Green]' =============================================================
   [/color][color=Blue]serout c.0[/color][color=Black],[/color][color=Blue]T2400_4[/color][color=Black],[/color][color=Blue]([/color][color=Navy]0[/color][color=Blue])  [/color][color=Green]'// Trigger interrupt on receive Picaxe
   [/color][color=Blue]pause [/color][color=Navy]4                 [/color][color=Green]'// Enough time for reciver to to jump to interrupt

    [/color][color=Blue]For [/color][color=Purple]b8 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]To [/color][color=Navy]12
        [/color][color=Blue]LookUp [/color][color=Purple]b8[/color][color=Black], [/color][color=Blue]( [/color][color=Red]"XYZZY"[/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7 [/color][color=Blue])[/color][color=Black], [/color][color=Purple]b9
        [/color][color=Blue]SerOut C.0[/color][color=Black],[/color][color=Blue]T2400_4[/color][color=Black],[/color][color=Blue]( [/color][color=Purple]b9 [/color][color=Blue])
    
    Next
 
return [/color]
[color=Green]'=================================================================[/color]


Receiver Code:

Code:
[color=Navy]#picaxe [/color][color=Black]14m2[/color]
[color=Navy]#no_data[/color]

[color=Green]'// Use a 10K pullup on serin Pin   (C.0 in this example)[/color]


[color=Blue]Start0:[/color]
[color=Green]'==================================[/color]
[color=Blue]setint [/color][color=Navy]%00000000[/color][color=Black],[/color][color=Navy]%00000001 [/color]
[color=Green]'==================================[/color]



[color=Blue]Start1:[/color]
[color=Green]'===============================================
  [/color][color=Blue]Suspend [/color][color=Navy]0  [/color][color=Green]'// no longer needed
  
  [/color][color=Blue]Do
    pause [/color][color=Navy]1000 [/color][color=Green]; waiting for serial data interrupt
  
  [/color][color=Blue]loop [/color]
[color=Green]'==============================================[/color]


[color=Blue]Start2:[/color]
[color=Green]'============================================== 
  [/color][color=Blue]Do
    Toggle C.2
    Pause [/color][color=Navy]500
  [/color][color=Blue]Loop[/color]
[color=Green]'==============================================[/color]



[color=Blue]INTERRUPT:[/color]
[color=Green]'==================================================================== 

 [/color][color=Blue]serin [PLAIN][[/PLAIN][/color][color=Navy]300[/color][color=Black],timeout[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black], [/color][color=Blue]c.0[/color][color=Black], [/color][color=Blue]T2400_4[/color][color=Black], [/color][color=Blue]([/color][color=Red]"XYZZY"[/color][color=Blue])[/color][color=Black],[/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7
   [/color][color=Blue]for [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]7 
     [/color][color=Blue]sertxd ([/color][color=Black]#[/color][color=Purple]@bptr[/color][color=Black],[/color][color=Red]" "[/color][color=Blue])   
   next 
   sertxd (cr[/color][color=Black],[/color][color=Blue]lf) 
   setint [/color][color=Navy]%00000000[/color][color=Black],[/color][color=Navy]%00000001  [/color][color=Green]'// enable interrupt     [/color]
[color=Blue]return

    [/color][color=Black]timeout:
        [/color][color=Blue]Sertxd ([/color][color=Red]"Timeout"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
        setint [/color][color=Navy]%00000000[/color][color=Black],[/color][color=Navy]%00000001  [/color][color=Green]'// enable interrupt    
    [/color][color=Blue]return[/color]
[color=Green]'==================================================================[/color]
 

Goeytex

Senior Member
Speed is power.

By abandoning parallel tasking the Picaxe speed can increased up to 32Mhz. This drastically improves serin performance by reducing command overhead time.

Here's how it can be done without using parallel tasking. With the Picaxe operating at 32MHz serin is good up to 19200 baud. Also note that there is now no need to add space between bytes on the TX side.

The blnking "task" is done inside the main loop while waiting for serial data. By breaking up the 500ms pause time into 200 small segments the blink rate remains steady when the serial data is processed in the interrupt routine. Here's some working code. I used a 14M2 for receive and a 20X2 to Send. Adjust pins and pause times for 18M2 or whatever Picaxe is used.

Transmit Code

Code:
[color=Black]Transmit_Data:[/color]
[color=Green]'=======================================================================[/color]
[color=Blue]for [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]7  [/color][color=Green]' Load b0 - b7 with incrementing values for testing
  [/color][color=Purple]@bptr [/color][color=DarkCyan]= [/color][color=Purple]B10
  [/color][color=Blue]inc [/color][color=Purple]b10[/color]
[color=Blue]next     



serout c.0[/color][color=Black],[/color][color=Blue]T19200_32[/color][color=Black],[/color][color=Blue]([/color][color=Navy]0[/color][color=Blue])  [/color][color=Green]'// Trigger interrupt on receive Picaxe[/color]
[color=Blue]pause [/color][color=Navy]4                   [/color][color=Green]'// Enough time for reciver to to jump to interrupt
                          '// and start serin   [/color]

[color=Blue]serout c.0[/color][color=Black],[/color][color=Blue]T19200_32[/color][color=Black], [/color][color=Blue]([/color][color=Red]"XYZZY"[/color][color=Black], [/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7 [/color][color=Blue])
    
return [/color]
[color=Green]'=================================================================[/color]

Receive Code

Code:
[color=Navy]#picaxe [/color][color=Black]14M2[/color]
[color=Navy]#no_data
#terminal 38400[/color]


[color=Black]INIT:[/color]
[color=Green]'======================================================[/color]
[color=Blue]setfreq m32[/color]
[color=Green]'// Use a 10K pullup on serin Pin  (C.0 in this example)[/color]

[color=Blue]setint [/color][color=Navy]%00000000[/color][color=Black],[/color][color=Navy]%00000001[/color]
[color=Green]'==================================================== [/color]


[color=Black]MAIN:[/color]
[color=Green]'=======================================================[/color]
[color=Blue]do
   
   for [/color][color=Purple]b10 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]200  [/color][color=Green]'// Break up into smaller pauses
     [/color][color=Blue]pause [/color][color=Navy]20
   [/color][color=Blue]next
     
   toggle c.2          [/color][color=Green]'// Blink the LED
    [/color]
[color=Blue]loop[/color]
[color=Green]'======================================================[/color]


[color=Blue]INTERRUPT:[/color]
[color=Green]'==================================================================== 

 [/color][color=Blue]serin [PLAIN][[/PLAIN][/color][color=Navy]3000[/color][color=Black],timeout[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black], [/color][color=Blue]c.0[/color][color=Black], [/color][color=Blue]T19200_32[/color][color=Black], [/color][color=Blue]([/color][color=Red]"XYZZY"[/color][color=Blue])[/color][color=Black],[/color][color=Purple]b0[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Purple]b7
   
   [/color][color=Blue]for [/color][color=Purple]bptr [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]7      [/color][color=Green]'// Display Received b0 - b7  Data in terminal 
     [/color][color=Blue]sertxd ([/color][color=Black]#[/color][color=Purple]@bptr[/color][color=Black],[/color][color=Red]" "[/color][color=Blue])   
   next 
   sertxd (cr[/color][color=Black],[/color][color=Blue]lf) 
   
   setint [/color][color=Navy]%00000000[/color][color=Black],[/color][color=Navy]%00000001  [/color][color=Green]'// enable interrupt     
   [/color][color=Blue]return

    [/color][color=Black]timeout:
        [/color][color=Blue]Sertxd ([/color][color=Red]"Timeout"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
        setint [/color][color=Navy]%00000000[/color][color=Black],[/color][color=Navy]%00000001  [/color][color=Green]'// enable interrupt    
    [/color][color=Blue]return[/color]
[color=Green]'==================================================================[/color]
 

Paix

Senior Member
Certainly a thread of interest. @Goeytex, I like you thinking and will have a play with your code. I know that you have spent significant time hacking the Picaxe serial facilities, so a lot of thought has gone into it. Many thanks.
 
Top