hsersetup for an 18M2 chip to communicate at 9600 baud 8N1?

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
 

hippy

Technical Support
Staff member
I would recommend getting the speech module working with an X2 first. Once we can get that working and understand what needs to be done we can then move on to figuring out what must be done for the 18M2.

Your Wait4Xternal routine is also flawed, doesn't check that a character has been received, doesn't wait until one has been, doesn't clearly show what was received, and also reports a 58 character was received even if it wasn't.

The code is also doing too much and should be greatly simplified to help debugging and getting it working.

But it's not worth worrying about that until the X2 is working.
 

SolidWorksMagi

Senior Member
Hi,

The 28X2 is working perfect with the Emic2 ... see the program listing on this page ... that's why I moved it to the 18M2 chip and started this new thread.
 
Last edited:

SolidWorksMagi

Senior Member
I modified the looping ReadyCheck routine ... but Emic2 is not controlling the program properly ??? The Emic2 seems to be reading the program code once it gets going and intermittantly actually performing the assigned tasks ??? very confusing ... After a round or two the hserin starts receiving a J instead of the 58 character ??? it's got to be some kind of com problem between the 18M2 and the Emic2 ...

Code:
; 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:
do
hserin ReadyChk
sertxd ( "Received character ",ReadyChk,cr,lf)
loop while ReadyChk <> 58 ;or Emic2Ready <> 13
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 * * * * * * * * * * * * * * * * * * * * * * * * *
please see
http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!
 
Last edited by a moderator:

SolidWorksMagi

Senior Member
Test a DO

Hi,

Trying to run just the small loop to see what is coming in from the Emic2 ... but I'm not sure my BASIC is correct since sertxd doesn't send the Emic2Ready character but just a blank back ???

Received character eceived character ceived character
Received character
Received character Received character Received character eceived character ceived character
Received character
Received character Received character Received character eceived character ceived character eived character
Received character
Received character Received character Received character eceived character ceived character
Received character
Received character Received character Received character eceived character ceived character
Received character
Receiveô


; TestEmic2.bas

#picaxe 18M2 ; Define the µProcessor IC Type
#terminal 4800

hsersetup B9600_4, %00

symbol Emic2Ready = b0

do while Emic2Ready <> 58
hserin Emic2Ready
sertxd ("Received character ",Emic2Ready,cr,lf)
loop
end



So then I tried rearranging the loop a little but still get the same blank result ... but I also noticed that the PC didn't get the whole message correct either ???


Received character
Received character rom the Emic2 and exited the doloop

I powered OFF and back ON and got;

Received character

Received character :
Received character : from the Emic2 and exited the doloop



; TestEmic2.bas

#picaxe 18M2 ; Define the µProcessor IC Type
#terminal 4800

hsersetup B9600_4, %00

symbol Emic2Ready = b0

do
hserin Emic2Ready
sertxd ("Received character ",Emic2Ready,cr,lf)
loop until Emic2Ready = 58 or Emic2Ready <> 13
sertxd ( "Received character ",Emic2Ready," from the Emic2 and exited the doloop",cr,lf)
end



When I trim down the do/loop it seems to work so I put it back into the subroutine instead of just the test and it fails ???

But the Emic2 isn't speaking ...


58 from the Emic2 and exited the doloop


do
hserin Emic2Ready
loop until Emic2Ready = 58 ;or Emic2Ready <> 13
sertxd ("58 from the Emic2 and exited the doloop",cr,lf)
return

It's as if after the first command assignment to the Emic2 gets passed, the loop checks for a ready and sends the second command assignment then the program faults.
 

SolidWorksMagi

Senior Member
Emic2 and the PICAXE 18M2 ... almost working ...

Using this Wait4Emic2: do/loop I decided to insert a sertxd line at each subroutine after the Emic2 command has been sent;

Wait4Emic2:
do
hserin Emic2Ready
loop until Emic2Ready = 58
sertxd ("58 from the Emic2 and exited the doloop",cr,lf)
return


Here's what happened ... the responses from the Emic2 seem exactly correct, but the Emic2 is not performing the commands correctly so it reads the commands instead of executing the commands ... but it does see the "S" for speak in front of the text it should read and reads the text. The Emic2 didn't play Song1 either, it just skips over that to the next text string ???

Kit Command ; First command is sent before the Wait4Emic2: do/loop
58 from the Emic2 and exited the doloop
Slowest Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Speak1 Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Song1 Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Fast Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Harry Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Speak2 Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Kit Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Slowest Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Speak1 Command ; Working correctly here ...
58 from the Emic2 and exited the doloop
Song1 Command ; Working correctly here ...
 

hippy

Technical Support
Staff member
Code:
loop until Emic2Ready = 58 or Emic2Ready <> 13
The problem there is that any value received other than 13 (CR) will cause the loop to terminate, including having not received a character.

Code:
Wait4Emic2:
do
hserin Emic2Ready
loop until Emic2Ready = 58
HSERIN will set the Emic2Ready variable to the last byte received, or leave it unchanged if there has been no byte received.

What probably happens is you get one colon, then the next time you check nothing else has been received so Emic2Ready retains the old colon which you then take as being a new colon.

You need something like -

Code:
Do
  Emic2Ready  = 0
  HSerIn Emic2Ready
Loop Until Emic2Ready = 58
However, that probably wont work reliably if the module sends back CR-LF-colon because there's only a two-deep buffer. You probably need to check for the CR using -

Code:
Do
  Emic2Ready  = 0
  HSerIn Emic2Ready
Loop Until Emic2Ready = CR
 

SolidWorksMagi

Senior Member
Code:
loop until Emic2Ready = 58 or Emic2Ready <> 13
The problem there is that any value received other than 13 (CR) will cause the loop to terminate, including having not received a character.

Code:
Wait4Emic2:
do
hserin Emic2Ready
loop until Emic2Ready = 58
HSERIN will set the Emic2Ready variable to the last byte received, or leave it unchanged if there has been no byte received.

What probably happens is you get one colon, then the next time you check nothing else has been received so Emic2Ready retains the old colon which you then take as being a new colon.

You need something like -

Code:
Do
  Emic2Ready  = 0
  HSerIn Emic2Ready
Loop Until Emic2Ready = 58
However, that probably wont work reliably if the module sends back CR-LF-colon because there's only a two-deep buffer. You probably need to check for the CR using -

Code:
Do
  Emic2Ready  = 0
  HSerIn Emic2Ready
Loop Until Emic2Ready = CR
That last do/loop is about the same as I've been trying this morning ... still with odd results back from the Emic2. I've asked support@Parallax.com and posted in their forums, but I'm not getting anything back so far.

I'm thinking that since the 28X2 sees a 13 and the 18M2 sees a 58 that maybe the Emic2 only sends a :cr or cr: ...

Still, I can't seem to reliably capture both characters as you can see in this loop;

Code:
do 
hserin Emic2Ready
loop until Emic2Ready = 58 or Emic2Ready = 13
return


weird thing is the control seems to be working okay but the Emic2 instead of switching to Fast mode just reads the command as; "no y five W two hundred and fifty" ... only sometimes sings the Song1 and sometimes gets stuck looping on one of the speak subroutines or song.

If I put the Emic2 on a BS2 it works perfectly ... so I think there must be some kind of timing error in the hserout port.
 

hippy

Technical Support
Staff member
Still, I can't seem to reliably capture both characters as you can see in this loop;

Code:
do 
hserin Emic2Ready
loop until Emic2Ready = 58 or Emic2Ready = 13
return
You do not have that Emic2Ready = 0 line within the loop. Without that the loop can exit prematurely when it should not exit at all.
 

SolidWorksMagi

Senior Member
You do not have that Emic2Ready = 0 line within the loop. Without that the loop can exit prematurely when it should not exit at all.
Hi,

Thanks ... I added that to the code ... but when I run the program, although it appears to see the Song1 subroutine, it skips singing and just performs the two Speak subroutines and their command subroutines ... It's as if the Emic2 is just sick of singing "Daisy" and so refuses to sing the song! But I'll try a "Normal" setting after the speak subroutines to see if that "cleans up" between the primary gosub calls ...

Code:
Wait4Emic2:
do 
Emic2Ready = 0
hserin Emic2Ready
loop until Emic2Ready = 58 or Emic2Ready = 13
return
Kit Command
Slowest Command
Speak1 Command
Song1 Command
Fast Command
Harry Command
Speak2 Command
Kit Command
Slowest Command
Speak1 Command
Song1 Command
Fast Command
Harry Command
Speak2 Command
Kit Command
Slowest Command
Speak1 Command
Song1 Command
Fast Command
Harry Command
Speak2 Command
Kit Command
 

SolidWorksMagi

Senior Member
Emic2 &amp; PICAXE 18M2 ... do/until loop messing up ???

Hi,

Seems the 18M2 hserin is maybe "flakey?" I don't know it seems like a timing problem at 9600 baud 8N1 ... but I've found the 18M2 on a AXE091 board seems to be losing communications back from the Emic2 ??? I'm wondering if I need to just send anything to the Emic2 when the do/until loop is failing ... just to get any character back from the Emic2 be it a : or ? or cr

Here is my entire program listing ... seems it should be working good now, but it's not;

Code:
; TestEmic2.bas

#picaxe 18M2    ; Define the µProcessor IC Type
#terminal 4800  ; 18M2 sends debug info back to PC

hsersetup B9600_4, %00

symbol Emic2Ready = b0

; BEGIN Main Body * * * * * * * * * * * * * * * * * * * * *
pause 3000

do
  gosub Kit
  gosub Slowest
  gosub Speak1   ; Message 1

  gosub Speech0  ; Emic2 English

  gosub Song1    ; Daisy

  gosub Speech2  ; Emic2 Spanish

  gosub Fast
  gosub Harry
  gosub Speak2   ; Message 2
loop
end
; END  Main Body * * * * * * * * * * * * * * * * * * * * **

; BEGIN Subroutines * * * * * * * * * * * * * * * * * * * *





; BEGIN Wait4Emic2 Subroutine * * * * *                             ; where things seem to be going wrong ???

Wait4Emic2:
do 
  Emic2Ready = 0
  hserin Emic2Ready
  loop until Emic2Ready <> 0                                                 ; It should be a 58 from the Emic2, but the program works better just looking for a change
return

; END Wait4Emic2 Subroutine * * * * * *





; Demo Speaks & Songs
Speak1:
  hserout 0, ("S", "This is Message 1. Kit speaking very slow",cr)
sertxd ("Speak1 Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
  gosub Normal
  gosub Wait4Emic2
return

Speech0:
  hserout 0, ("D0",cr)
sertxd ("Speech0 Command",cr,lf)  ; Debug messages back to the PC
  gosub Normal
  gosub Wait4Emic2
return

Song1:
  hserout 0, ("D1",cr)
sertxd ("Song1 Command",cr,lf)  ; Debug messages back to the PC
  gosub Normal
  gosub Wait4Emic2
return

Speech2:
  hserout 0, ("D2",cr)
sertxd ("Speech2 Command",cr,lf)  ; Debug messages back to the PC
  gosub Normal
  gosub Wait4Emic2
return

Speak2:
  hserout 0, ("S", "This is Message 2. Harry speaking  Fast",cr)
sertxd ("Speak2 Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
  gosub Normal
  gosub Wait4Emic2
return


; Voices
Paul:
  hserout 0,("N0",cr)  ; Perfect Paul (Paulo) Voice
  gosub Wait4Emic2
return

Harry:
  hserout 0,("N1",cr)  ; Huge Harry (Francisco) Voice
sertxd ("Harry Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Betty:
  hserout 0,("N2",cr)  ; Beautiful Betty Voice
sertxd ("Betty Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Ursula:
  hserout 0,("N3",cr)  ; Uppity Ursula Voice
sertxd ("Ursula Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Dennis:
  hserout 0,("N4",cr)  ; Doctor Dennis (Enrique) Voice
sertxd ("Dennis Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Kit:
  hserout 0,("N5",cr)  ; Kit the Kid Voice
sertxd ("Kit Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Frank:
  hserout 0,("N6",cr)  ; Frail Frank Voice
sertxd ("Frank Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Rita:
  hserout 0,("N7",cr)  ; Rough Rita Voice
sertxd ("Rita Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Wendy:
  hserout 0,("N8",cr)  ; Whispering Wendy (Beatriz) Voice
sertxd ("Wendy Speaking",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return


; Voice Speeds
Slowest:
  hserout 0,("W75",cr)   ; Slowest Speech
sertxd ("Slowest Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Slow:
  hserout 0,("W100",cr)  ; Slow Speech
sertxd ("Slow Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Normal:
  hserout 0,("R",cr)     ; Default Speech Settings
sertxd ("Normal Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Fast:
  hserout 0,("W250",cr)  ; Fast Speech
sertxd ("Fast Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Faster:
  hserout 0,("W300",cr)  ; Faster Speech
sertxd ("Faster Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return

Fastest:
  hserout 0,("W400",cr)  ; Fastest Speech
sertxd ("Fastest Command",cr,lf)  ; Debug messages back to the PC
  gosub Wait4Emic2
return
end
; END Subroutines * * * * * * * * * * * * * * * * * * * * * * * * *
; VOICES:
;0: Perfect Paul (Paulo)
;1: Huge Harry (Francisco)
;2: Beautiful Betty
;3: Uppity Ursula
;4: Doctor Dennis (Enrique)
;5: Kit the Kid
;6: Frail Frank
;7: Rough Rita
;8: Whispering Wendy (Beatriz) 


;  COMMAND SET: 
;Sx Convert text-to-speech:
;x = message (1023 characters maximum)
;Dx Play demonstration message: x = 0 (Speaking), 1 (Singing), 2 (Spanish)
;X Stop playback (while message is playing)
;Z Pause/un-pause playback (while message is playing)
;Nx Select voice: x = 0 to 8
;Vx Set audio volume (dB): x = -48 to 18
;Wx Set speaking rate (words/minute): x = 75 to 600
;Lx Select language: x = 0 (US English), 1 (Castilian Spanish), 2 (Latin Spanish)
;Px Select parser: x = 0 (DECtalk), 1 (Epson)
;R Revert to default text-to-speech settings
;C Print current text-to-speech settings
;I Print version information
;H Print list of available commands


; Emic2 LED:
;1. Green: Idle state. Waiting for a valid command to be sent by the host.

;2. Red: Active state. For example, during a text-to-speech conversion.

;3. Orange (Solid): Initialization state. Occurs on power-up only. 
;      Emic 2 takes approximately three seconds to properly initialize on power-up 
;      before it is ready to receive commands.   

;4. Orange (Blinking): Error state. Emic 2 has malfunctioned 
;      due to an on-board communication error. 
;      If a power cycle of Emic 2 does not remedy the situation, 
;      please contact Parallax technical support for further assistance.
 

SolidWorksMagi

Senior Member
Emic2 w/PICAXE 18M2 ... timing on a do/until loop and hserin ???

Hi,

Very strange ... I inserted the debug line (sertxd ("Emic2 Replies with a",Emic2Ready,cr,lf) ; Debug messages back to the PC) and now the program is working just fine ??? I guess I could just use a small pause instead just to slow down the do/until loop.

Wait4Emic2:
do
Emic2Ready = 0
hserin Emic2Ready
sertxd ("Emic2 Replies with a",Emic2Ready,cr,lf) ; Debug messages back to the PC
loop until Emic2Ready <> 0 ;= 58 or Emic2Ready = 13
return
 

hippy

Technical Support
Staff member
Seems the 18M2 hserin is maybe "flakey?"
It is more likely to be some other issue, such as your code.

For example you are now exiting the Wait4Emic2 loop when any non-zero character is received, but that doesn't take account of the two-byte buffer. That could lead to it appearing as if a second command has completed before it has.
 

hippy

Technical Support
Staff member
I'm not seeing how to look for two or three incoming bytes from the Emic2 on the 18M2 hserin command line in the online manual
You can't. One would have to do that programmatically and it might not be possible in all circumstances, may require a different approach to solving the issue faced.
 

Goeytex

Senior Member
Seems the 18M2 hserin is maybe "flakey?"
M2 Hserin is not flakey. But it is completely different from X2 Hserin. It does not receive data into the scratchpad as your commented code indicates. It can only receive 2 byte before they must be processed by code or any data after that will be lost. This gives it very limited functionality and IMO is a poor implementation of hardware serial receive functionality.
.
Why you are using M2 hardware serin for such a simple application is a mystery to me. Testing for a received character is much easier with software serin as was suggested by hippy in the other thread.

All you need to do is:

1. Use setfreq to set the Picaxe to 16Mhz/
2. Use serout to send data to the EMIC
3. Use serin with a qualifier to detect the colon character

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

[color=Blue]setfreq M16[/color]

[color=Black]Main:[/color]

[color=Blue]do
   gosub [/color][color=Black]Task1
  [/color]
[color=Blue]loop   
   
   [/color]
[color=Black]Task1:   [/color]
[color=Blue]serout b.5[/color][color=Black],[/color][color=Blue]T9600_16[/color][color=Black],[/color][color=Blue]([/color][color=Red]"S"[/color][color=Black],[/color][color=Red]"Hello"[/color][color=Black],[/color][color=Blue]cr)
gosub [/color][color=Black]WaitForReady      [/color]
[color=Blue]return[/color]

[color=Black]WaitForReady:[/color]
[color=Blue]serin b.2[/color][color=Black],[/color][color=Blue]T9600_16[/color][color=Black],[/color][color=Blue]([/color][color=Red]":"[/color][color=Blue])
return[/color]
 

jims

Senior Member
According to the Emic 2 PDF document; the Emic 2 could also send a "?" response if it receives an invalid command. Can RCV data from the serin command be used to determine what to do next? A "select case" maybe based on the RCV data? Jims
 

hippy

Technical Support
Staff member
According to the Emic 2 PDF document; the Emic 2 could also send a "?" response if it receives an invalid command. Can RCV data from the serin command be used to determine what to do next? A "select case" maybe based on the RCV data? Jims
Probably. It all depends on what the Emic 2 actually and exactly sends back. If it is CR-LF-: and CR-LF-? that could be caught with b0 left holding ":" or "?" using -

SerIn RX, BAUD, ( CR, LF ), b0

It would also be possible to add a timeout to that and it could be adjusted for any consistent response from the module.

Not sure it would help though because we shouldn't be seeing any response with other than a colon in it, the BOE code would not work if it wasn't getting that colon.

The problem we have here is that we don't know exactly what the Emic 2 should be sending back, is sending back, or why previous efforts to detect the colon do not seem to have worked.
 

jims

Senior Member
Hippy.... I sent this request to the Emic 2 support yesterday. Hopefully they will respond with good info. Jims
Thanks for responding. I should receive my Emic 2 within the next 2 weeks. Trying to put together code to run the Emic2 and I have two questions....
1. When the Emic 2 returns the : is the : the only data byte xmitted, or do other characters such as cr....lf.... come with it?
2. What is the approximate turnaround time from when the Emic 2 receives a command until it xmits a response?
Thank you,
Jim S
 

hippy

Technical Support
Staff member
It would be interesting to see what SolidWorksMagi results and your own are with the following code using any X2 if you have one -

Code:
#Picaxe 28X2
#Terminal 9600
HserSetup B9600_8, %001
Do
  Pause 3000
  SerTxd( "Sending", CR, LF )
  HserOut 0, ( "S", "Hello", CR )
  Do 
    Pause 1000
  Loop While ptr = hSerPtr    
  Pause 1000
  Do
    SerTxd( "Received ", #@ptrInc, CR, LF )
  Loop while ptr <> hSerPtr
  SerTxd( "Done", CR, LF, CR, LF )
Loop
 

Goeytex

Senior Member
I posted code on the other thread that will show exactly what the EMIC2 sends back. However it seems that it was ignored by the OP. IF that code was run then there would be no doubt as to what the EMIC returns. Then knowing exactly what is sent and the order of what is sent, a better app could be written that tests for both ":" and "?".
 

jims

Senior Member
I expect to have my Emic 2 in a week to 10 days. Will try all of your good suggestions when I do get it. Question???? If running an M2 chip without using the background receive feature; is possible that the M2 Hasn't turned around (isn't ready to receive) when the Emic 2 begins to transmit? I would think that this is possible if there is a lot of processing between the M2 XMIT and RCV. What is the M2 turn around time from when it XMITs until it's ready to RCV? Jims
 

Goeytex

Senior Member
Not likely this will be a problem since serin is already waiting while the message is still playing. It only take about 200us more or less for the program to jump from serout to serin depending upon how the code is written.
 

hippy

Technical Support
Staff member
What Goeytex says. If you only checked for the colon response, assuming it is preceded by CR or CR-LF, those two bytes would take 1ms or 2ms so a SERIN should be ready to see the colon when it arrives. The operating speed could be increased to shorten the turn-round execution speed of SEROUT to SERIN. HSEROUT would allow turn-round while the CR were being transmitted.

HSERIN would be ready even before you sent the command and could be used providing you were willing to accept the CR or LF as if the colon reply.

Added : An interesting point though about playing while the turn-round occurs. This may not be the case for some commands which just change parameters and don't play anything, so perhaps that is the issue in SolidWorksMagi's code ? It shouldn't however be a problem with the X2 code using background receive.
 

jims

Senior Member
Hippy.... I sent this request to the Emic 2 support yesterday. Hopefully they will respond with good info. Jims
Thanks for responding. I should receive my Emic 2 within the next 2 weeks. Trying to put together code to run the Emic2 and I have two questions....
1. When the Emic 2 returns the : is the : the only data byte xmitted, or do other characters such as cr....lf.... come with it?
2. What is the approximate turnaround time from when the Emic 2 receives a command until it xmits a response?
Thank you,
Jim S
Here's the response from the Emic 2 support.
.....................................................................
Jims

I just connected the Emic 2 to my PC via our Prop Plug and used the Parallax Serial Terminal to see what is being sent on power-up. At power-up there is a delay while the Emic initializes and then it appears to send a linefeed (not sure if a carriage return is sent with it, but since the command set uses CR/LF I am assuming both. After that the colon : appears. That is it. No other text is sent upon power-up.

As for the turnaround time that depends on the command. When you send a command the Emic executes it and the returns the colon again. In the case of text this is not sent until the speech is done being sent.

Respectfully,
Engineering Tech, Parallax Inc.
...................................................................
Hopefully this will help us to understand more about this Emic 2 "text to speech" module.
I'm still waiting to get my hardware. Jims
 
Top