SolidWorksMagi
Senior Member
Hi,
I think I'm having a baud rate problem ... the online docs seem to say for an 18M2 the hsersetup should be;
hsersetup B9600_4, %00
That seems to sort of work ... but my program is not being controlled by the external device as I would expect.
The external device looks for a command, then sends back a : character 58 when it is ready for the next command.
What is happening is that some of the subroutines get performed perfectly in one pass, then are screwed up in the next pass while other subroutines are screwed up in the first pass then perform perfectly in another pass ???
Here's the program I'm using;
; ControlFromExternal.bas
#picaxe 18M2 ; Define the µProcessor IC Type
#terminal 4800
hsersetup B9600_4, %00
symbol ReadyChk = b0
; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
pause 3000
do
gosub TASK1
gosub TASK2
gosub TASK3
gosub TASK4
loop
end
; END Main Body * * * * * * * * * * * * * * * * * * * * **
; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * *
; BEGIN Wait4Xternal Subroutine * * * * *
Wait4Xternal:
hserin ReadyChk ;Receive 1 byte into scratchpad location 0
if ReadyChk <> 58 then gosub timeout ; Looking for a : from the external device
sertxd ( "Received 58 character",cr,lf)
return
timeout:
sertxd ( "Received a ",ReadyChk," character",cr,lf)
return
; END Wait4Xternal Subroutine * * * * * *
; BEGIN TASK Assignments * * * * * * * * * *
TASK1:
gosub Kit
gosub Slow
hserout 0, ("S", "TEXT 1 SENT 2 EXTERNAL DEVICE",cr)
gosub Wait4Xternal
return
TASK2:
hserout 0, ("D0",cr)
gosub Wait4Xternal
return
TASK3:
hserout 0, ("D1",cr)
gosub Wait4Xternal
return
TASK4:
gosub Fast
gosub Harry
hserout 0, ("S", "TEXT 2 SENT 2 EXTERNAL DEVICE",cr)
gosub Wait4Xternal
return
; END TASK Assignments * * * * * * * * * *
; BEGIN Utility Control Subroutines * * * * * * * * * * * *
Harry:
hserout 0,("N1",cr) ; Voice 1
gosub Wait4Xternal
return
Kit:
hserout 0,("N5",cr) ; Voice 5
gosub Wait4Xternal
return
Slow:
hserout 0,("W100",cr) ; Slow TTS
gosub Wait4Xternal
return
Fast:
hserout 0,("W250",cr) ; Fast TTS
gosub Wait4Xternal
return
; END Utility Control Subroutines * * * * * * * * * * * *
; END Subroutines * * * * * * * * * * * * * * * * * * * * * * * * *
This is the results in the "Serial Termanl" screen set at 4800 baud;
Îo{Ùived 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received a
character
Received 58 character
Received 58 character
Received a ? character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
I think I'm having a baud rate problem ... the online docs seem to say for an 18M2 the hsersetup should be;
hsersetup B9600_4, %00
That seems to sort of work ... but my program is not being controlled by the external device as I would expect.
The external device looks for a command, then sends back a : character 58 when it is ready for the next command.
What is happening is that some of the subroutines get performed perfectly in one pass, then are screwed up in the next pass while other subroutines are screwed up in the first pass then perform perfectly in another pass ???
Here's the program I'm using;
; ControlFromExternal.bas
#picaxe 18M2 ; Define the µProcessor IC Type
#terminal 4800
hsersetup B9600_4, %00
symbol ReadyChk = b0
; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
pause 3000
do
gosub TASK1
gosub TASK2
gosub TASK3
gosub TASK4
loop
end
; END Main Body * * * * * * * * * * * * * * * * * * * * **
; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * *
; BEGIN Wait4Xternal Subroutine * * * * *
Wait4Xternal:
hserin ReadyChk ;Receive 1 byte into scratchpad location 0
if ReadyChk <> 58 then gosub timeout ; Looking for a : from the external device
sertxd ( "Received 58 character",cr,lf)
return
timeout:
sertxd ( "Received a ",ReadyChk," character",cr,lf)
return
; END Wait4Xternal Subroutine * * * * * *
; BEGIN TASK Assignments * * * * * * * * * *
TASK1:
gosub Kit
gosub Slow
hserout 0, ("S", "TEXT 1 SENT 2 EXTERNAL DEVICE",cr)
gosub Wait4Xternal
return
TASK2:
hserout 0, ("D0",cr)
gosub Wait4Xternal
return
TASK3:
hserout 0, ("D1",cr)
gosub Wait4Xternal
return
TASK4:
gosub Fast
gosub Harry
hserout 0, ("S", "TEXT 2 SENT 2 EXTERNAL DEVICE",cr)
gosub Wait4Xternal
return
; END TASK Assignments * * * * * * * * * *
; BEGIN Utility Control Subroutines * * * * * * * * * * * *
Harry:
hserout 0,("N1",cr) ; Voice 1
gosub Wait4Xternal
return
Kit:
hserout 0,("N5",cr) ; Voice 5
gosub Wait4Xternal
return
Slow:
hserout 0,("W100",cr) ; Slow TTS
gosub Wait4Xternal
return
Fast:
hserout 0,("W250",cr) ; Fast TTS
gosub Wait4Xternal
return
; END Utility Control Subroutines * * * * * * * * * * * *
; END Subroutines * * * * * * * * * * * * * * * * * * * * * * * * *
This is the results in the "Serial Termanl" screen set at 4800 baud;
Îo{Ùived 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received 58 character
Received a
character
Received 58 character
Received 58 character
Received a ? character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character
Received 58 character
Received a
character