serrxd/sertxd

Wingrider

New Member
Please help
I have been working on the serrxd code for three days with little luck.
The program has worked for years in the real world using button presses as control inputs.
what I am trying to do now is replace the button press inputs.
By doing this I replace 3 button press inputs with one serrxd command and can
monitor for all buttons.


if I use serrxd ($10) the program executes
if I use serrxd ($10),b1 the program executes if I don't check the value of b1
but if I use serrxd($10,$03) it doesn't

the sertxd works fine and I can send any data I want to the Navigation board and it responds as expected.
I know that the serrxd will wait until it receives the qualifier which is what I want.
I know that the baudrate should be 19200. Anything else and Command_1 don't work.
To test the baudrate I commented out the serrxd and Command_1 works
I know the sequence I am looking for is on the data line. It is the first 7 characters of the
commands. Also $10,$03 is constantly on the data line.

What I am trying to do is read the data line for the following sequence.

serrxd($10,$03,$10,$8A,$0C,$01,$00),b1

The value of b1 determines which button has been pressed and so
which command will be executed.



#picaxe 08m2
setfreq M16
Disconnect
Main: ' Main loop

' Wait for data on Serial_line at startup
Serrxd($10,$03) ' Wait for Data line to initialize
wait 60
gosub Command_1
Stop
Command_1:

pause 250

sertxd ($10,$03,$10,$8A,$0C,$01,$00,$41,$CC,$10,$10,$36,$12,$00,$F1,$F5,$F5,$80,$A9)
sertxd ($10,$03,$10,$8A,$0C,$02,$00,$41,$CC,$30,$75,$12,$00,$F1,$F5,$F5,$80,$49)

pause 500
return
 

BESQUEUT

Senior Member
Please help
I have been working on the serrxd code for three days with little luck.
The program has worked for years in the real world using button presses as control inputs.
what I am trying to do now is replace the button press inputs.
By doing this I replace 3 button press inputs with one serrxd command and can
monitor for all buttons.
Please : use
Code:
 ... [/ CODE] when you publish some code,or use "right/clic" copy for forum...

So, you are using a first Picaxe to send data to another one ?

Your "main loop" does not loop ?

Maybe you can use a
DO ... LOOP
and add a timeout to the serrxd, so few chances to get correct sequence ?
 
Last edited:

techElder

Well-known member
Wingrider, you should explain what kind of equipment you are trying to send something to. Perhaps you are only testing with the editor's built-in Terminal program?
 

AllyCat

Senior Member
Hi,

Note that the DISCONNECT is probably not necessary as it's automatically generated by SERRXD, but I would put a RECONNECT before the STOP to (perhaps) remove the need for a Hardware Reset procedure every time before reprogramming.

However, my suspicion is that M16 is not sufficiently fast to run software serial comms reliably at 19200 baud. Have you tried M32 ?

Cheers, Alan.
 

hippy

Technical Support
Staff member
Perhaps the problem is with what is being sent rather than being received. It could be the receiver is simply waiting for something which never actually arrives, or never arrives as far as the PICAXE is concerned.
 

Wingrider

New Member
See if this is better. Sorry for the first post.Hopefully the code pasted correctly.

The code I am waiting for is the same as the first four characters as in the sertxd command.The control panel encodes the key board and send the command to the Navigation board.
The program is monitoring the data line between the control panel and the navigation board.
This is the code that is being sent to the navigation board by the control panel if I manually press the Menu button.
The sertxt code work perfectly. If I comment out the serrxd line the menu displays on the Navigation display.

Hippy thank you for your help. It does not seem to be the output. I can put any of the button/key codes in the sertxt command and they will work. I can put a combination of button/key codes
in the sertxt command and they will work a expected.But if I try to monitor for anything more than 1 character/byte it is a no go. These key codes came from the data stream between the control panel
and the navigation board.

AllyCat thank you for your help. I do realize there are a couple of redundant commands in my code. I went from M4 to M16, M16 worked on the output but I am going to try M32 as soon as I finish this post.
Everyone else thank you for you post and help. I appreciate all the help I can get.


Code:
    [color=Green]' Navigation Menu Command
    ' 
    ' This program waits for the data sequence $10,$03,$10,$8A then
    ' sends the Menu command to the Navigation board
    '
    ' ********************    Outputs  **********************************   

    [/color][color=Blue]symbol    Serial_line     [/color][color=DarkCyan]= [/color][color=Blue]C.4   [/color][color=Green]' Serial control line IC pin 3
     
    '  ********************    Init  ************************************    :
    [/color][color=Navy]#picaxe [/color][color=Black]08m2  
    [/color][color=Blue]setfreq M16   
    Disconnect    
    
    [/color][color=Black]Main:                              [/color][color=Green]' Main loop
     
      ' Wait for data on Serial_line at startup
      [/color][color=Blue]low Serial_line         [/color][color=Green]' Open Speed_sense line  
      [/color][color=Blue]wait [/color][color=Navy]1
      [/color][color=Blue]Serrxd ([/color][color=Navy]$10[/color][color=Blue])             [/color][color=Green]' Test works
     ' Serrxd($10,$03,$10,$8A)      ' Wait for menu commnand doesn't work
                        
     ' Send Menu command
      [/color][color=Blue]high serial_line
      pause [/color][color=Navy]500
      [/color][color=Blue]sertxd  ([/color][color=Navy]$10[/color][color=Black],[/color][color=Navy]$03[/color][color=Black],[/color][color=Navy]$10[/color][color=Black],[/color][color=Navy]$8A[/color][color=Black],[/color][color=Navy]$0C[/color][color=Black],[/color][color=Navy]$01[/color][color=Black],[/color][color=Navy]$00[/color][color=Black],[/color][color=Navy]$41[/color][color=Black],[/color][color=Navy]$CC[/color][color=Black],[/color][color=Navy]$10[/color][color=Black],[/color][color=Navy]$10[/color][color=Black],[/color][color=Navy]$36[/color][color=Black],[/color][color=Navy]$12[/color][color=Black],[/color][color=Navy]$00[/color][color=Black],[/color][color=Navy]$F1[/color][color=Black],[/color][color=Navy]$F5[/color][color=Black],[/color][color=Navy]$F5[/color][color=Black],[/color][color=Navy]$80[/color][color=Black],[/color][color=Navy]$A9[/color][color=Blue])
      sertxd  ([/color][color=Navy]$10[/color][color=Black],[/color][color=Navy]$03[/color][color=Black],[/color][color=Navy]$10[/color][color=Black],[/color][color=Navy]$8A[/color][color=Black],[/color][color=Navy]$0C[/color][color=Black],[/color][color=Navy]$02[/color][color=Black],[/color][color=Navy]$00[/color][color=Black],[/color][color=Navy]$41[/color][color=Black],[/color][color=Navy]$CC[/color][color=Black],[/color][color=Navy]$30[/color][color=Black],[/color][color=Navy]$75[/color][color=Black],[/color][color=Navy]$12[/color][color=Black],[/color][color=Navy]$00[/color][color=Black],[/color][color=Navy]$F1[/color][color=Black],[/color][color=Navy]$F5[/color][color=Black],[/color][color=Navy]$F5[/color][color=Black],[/color][color=Navy]$80[/color][color=Black],[/color][color=Navy]$49[/color][color=Blue])

      pause [/color][color=Navy]500    
      [/color][color=Blue]low Serial_line               [/color][color=Green]' Close serial data line control line
    
   [/color][color=Blue]stop[/color]
 

Wingrider

New Member
AllyCat

tried M32 and no joy. With the m32 command the output stopped being recognized by the Navigation board. back to m16 and the output works again.
 

hippy

Technical Support
Staff member
Your receiver gets the initial $10,$03, then does a WAIT 60. There's no equivalent delay in your sending program. What you will be looking for will have been well and truly gone and lost by then.
 

AllyCat

Senior Member
Hi,

Don't forget that the PAUSEs and SERRXD baud rate will change at M32 !

However, it appears that you may be able to use SERIN on the Programming input of an 08M2 (c.5) and probably any M2 except the 20M2 (which doesn't have port.pin name), so you should be able to set 9200 baud at M32.

With a POKESFR, it's also possible to use HSERIN on that pin, but only with "True" (Idle High) data polarity. :(

Cheers, Alan.
 

Wingrider

New Member
Your receiver gets the initial $10,$03, then does a WAIT 60. There's no equivalent delay in your sending program. What you will be looking for will have been well and truly gone and lost by then.
Hippy
I have posted a program in post #6 that hopefully makes things simpler and clearer.
Sorry for the OP .

This is a trouble shooting program to find out why the serrxd command isn't working in the original program. If I execute this program and the display switches to the Menu screen
then I know the serrxd ($10,$03) was detected properly. If the Menu display doesn't show up it didn't.

All the serrxd ($10,$03) does is verify that valid data is being received from the control panel. If and when I get that command working the command will be expanded to serrxd($10,$03,$10,$8A,$0C,$01,$00),b1. But until I get serrxd($10,$03) to work there is no reason to try serrxd($10,$03,$10,$8A,$0C,$01,$00),b1.
b1 will then be stored in a variable and then a select case command will determine which button/key was pressed.
 

techElder

Well-known member
Ok, perhaps this is a silly question.

Why are you using SERTXD/SERRXD to start with? Wouldn't one of SERIN/SEROUT or HSERIN/HSEROUT be useful?

My understanding of SERTXD/SERRXD is that they are tied to specific legs on a PICAXE and baudrate is tied to processor frequency. Is this what you are designing for?

Just asking for clarification.
 

Wingrider

New Member
Ok, perhaps this is a silly question.

Why are you using SERTXD/SERRXD to start with? Wouldn't one of SERIN/SEROUT or HSERIN/HSEROUT be useful?

My understanding of SERTXD/SERRXD is that they are tied to specific legs on a PICAXE and baudrate is tied to processor frequency. Is this what you are designing for?

Just asking for clarification.
No not a silly question and No. The feature I want to exploit is the fact the serrxd will monitor the data line and not execute/proceed until it sees the data string I am looking for.
The serrxd command wont execute until string ($10,$03,$10,$8A,$0C,$01,$00) is received. When that string is received ,in the actual program, the next character received , b1, is loaded into a variable. The value of the variable determines where the program branches off to, then send a command to the navigation board and then wait for the next serrxd to execute.

Please ignore the code in the my first post.
The code I posted in post 7,or maybe 8 is just for trouble shooting the serrxd or what ever command I use. The rest of the program works perfectly and has been for 5 or 6 years with the exception for this command which is new to the program.

At this point I believe it has something to do with the data being monitoring. Later today I am going the try and monitor the input data with the Terminal command.

Thank you for your time. All help is appreciated .
 

Wingrider

New Member
Ok I monitored the incoming data from the control panel with the Picaxe terminal command. this is the first few line of data. I actually log the input for 1 minute and [10][03] is all thru the data. I initialized two places were the [10][03] is.
I assume it has some thing to do with the delimiter and how the code is reading it. Also while in terminal mode I sent the $10,$03 and the code executed.
Can some one tell me how to represent [10][03] in the serrxd command.

[10][8A]
[04][00][01][C0][07][07][F9][12][00][F1][00][00][00][9A][10][03][10][8A][0C][05][00][01][C0][04][00][12][00][F1][00][00][00][9D][10][03][10][8A]
[00][00][01][C0][FF]"p[12][00][F1][00][00][00][14][10][03][10][8A][0C][01][00][01][C0][15]6[12][00][F1][00][00][00]Z[10][03][10][8A][0C][02][00]
[01][C0][F2][85][12][00][F1][00][00][00]-[10][03][10][8A][0C][C3][00][01][C0][82]R[03][11][FF][97]?[80][A9][10][03]bBq[80]@[E0][D0]P&[14][BA]
[10][03][10][8A][C5][00][01][C0][04][00][14][0F][00][00][BF][10][03][10][8A][0B][80][C0][04][F7]"p[14][0F][00][00]v[10][03]Wd[92][02][14]
[00][00][00][9A][10][03][10][8A][0C][82][00][01][C0][F2][85][12][00][F1][00][00][00][AD][10][03][10][8A][0C]C[00][01][C0][82]R[12][00][F1][00][00]
[00][8F][10][03][10][8A]
 
Last edited:

hippy

Technical Support
Staff member
The serrxd command wont execute until string ($10,$03,$10,$8A,$0C,$01,$00) is received.
And you should be able to achieve that with -

SerRxd ( $10,$03,$10,$8A,$0C,$01,$00 ), b1

And you should be able to send data which is received by that using -

SerTxd ( $10,$03,$10,$8A,$0C,$01,$00, b1 )

The data sent can be in any byte variable and you could alternatively use SEROUT.

You can test that works with ...

Code:
#Picaxe 08M2
Sender:
  Do
    SerTxd ( $10,$03,$10,$8A,$0C,$01,$00, b1 )
    Pause 1000
  Loop
Code:
#Picaxe 08M2
  Symbol LED = C.?
Receiver:
  Disconnect
  Do
    Low LED
    SerRxd ( $10,$03,$10,$8A,$0C,$01,$00 ), b1
    High LED
    Pause 250
  Loop
If it's working the receiver LED should flash once a second. Get that working and then you can start adding SETFREQ, checking it still works.
 

AllyCat

Senior Member
Hi,

I know that the serrxd will wait until it receives the qualifier which is what I want.
I know that the baudrate should be 19200.
I still question why you are using SERRXD and not SERIN. Also is 19200 baud what you need, or just calculated to use with SERRXD at M16 ?

AFAIK, SERIN c.5,N19200_16,($10,$03),b1 should do exactly the same thing (with an 08M2) but gives the opportunity to experiment with different clock/baud rates. The PICaxe interpreter is known to struggle with higher baud rates at lower clock frequencies.

Cheers, Alan.
 

Wingrider

New Member
Hippy and AllyCat

I have tried both of your codes and about every baud rate possible. The only thing that works is with just one character in either of serrxd or serin. No matter what the speed/baudrate combination nothing else works. I monitored the input steam to c.5 with the #terminal and it looks good at 19200. Every other baudrate either give garbage or locks up the terminal program.

At this point I am going to try my other project board and a different chip. I'm wondering if maybe it is the chip.

AllyCat
I apologize for not taking your advise about serin before but I mis understood that command.

Thank you both for your help. I will update the thread once I the other board up and running.
 

hippy

Technical Support
Staff member
I monitored the input steam to c.5 with the #terminal and it looks good at 19200. Every other baudrate either give garbage or locks up the terminal program.
I would guess that's because you have the Terminal still set to 19200 baud from previous testing.
 

Wingrider

New Member
I would guess that's because you have the Terminal still set to 19200 baud from previous testing.

I changed the baudrate of the terminal window while monitoring the data line directly from the control panel before the picaxe. The pic was not in the circuit
while running these baudrate test.

to clarify I used the baudrate window in the upper left corner of the picaxe terminal program. I changed all the setting one at a time and the only one that seemed
to display good data was 19200,8,1,n .

Change project board and pic chip. No difference. Next step is to change the input pin to C.1 from C.5 which is not use at this time.
Again thanks for your help.
 

Buzby

Senior Member
I changed the baudrate of the terminal window while monitoring the data line directly from the control panel before the picaxe.
I've had problems with my PC accepting on-the-fly baud rate changes from the PE6 terminal, so I always shut it down and start again.

Never got to bottom of why it was only PE6 that had this issue.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
to clarify I used the baudrate window in the upper left corner of the picaxe terminal program. I changed all the setting one at a time and the only one that seemed to display good data was 19200,8,1,n .
Did you adjust the 'control panel' to output at other than 19200 baud; if not it will still be using 19200 baud.
 

Wingrider

New Member
Did you adjust the 'control panel' to output at other than 19200 baud; if not it will still be using 19200 baud.
Dang didn't think about that.

I need to lay off this project for a few days . But will get back when I look at it again.

Again thanks to everyone for your help.
 

Wingrider

New Member
Finally returned to this project Sorry for the long delay. Was able to read the input with
setfreq M32

serin C.1,N19200_32,($10,$03,$10,$08),b0

the above works great but the following doesn't seem to work

setfreq M16

serin C.1,N19200_16,($10,$03,$10,$08),b0

Shouldn't they both work ?
 

inglewoodpete

Senior Member
SerIn is a bit-banged command and does not use a UART. So the PICAXE constantly monitors the state of the input pin and times and pieces together the bits as they arrive on the pin. Once 8 bits have been received, the byte is stored in the specified variable, before the process starts again for the next byte. Due to the overhead time required to assemble and save the received byte, successive start bits could be lost and the data appears to arrive in a garbled state.

M16 speed may not be fast enough to complete the storage of a byte before the next start bit arrives. It sounds as if M32 is fast enough to receive and store the data. Can the sender of the data insert a short pause between each byte of data? Otherwise, you may need to use a pin that has an internal UART, allowing hardware serial data reception.
 

techElder

Well-known member
Put your thinking cap on there, Wingrider, and make one change at a time to something that can effect your results.

For instance, going with what inglewoodpete says, see if the next baud rate slower will receive as the M32 test did. Adjust your parameters until you find out which one works best. That's all any of us has ever done to solve a problem. Good luck!

serin C.1,N19200_32,($10,$03,$10,$08),b0
serin C.1,N19200_16,($10,$03,$10,$08),b0
 

hippy

Technical Support
Staff member
I would tend to agree with inglewoodpete's analysis of the problem; at M16 the PICAXE isn't quick enough to handle the incoming data stream but at M32 is.
 
Top