Using the serrxd command.

jehill39

Active member
I am monitoring the frequency of VFO A on an amateur radio transceiver by connecting my 14M2 programming port to a utility that monitors VFO A and provides a continuous output in the following ASCII character format at 4800 baud:

"FAxxxxxxxxxxx;", where x is a decimal digit 0-9

Here is an excerpt from the code using the serrxd command:

; THE CODE

; First let's define some helpful symbols.

; The PICAXE outputs to be used to control the six antennas:
symbol ANT1 = B.0
symbol ANT2 = B.1
symbol ANT3 = B.2
symbol ANT4 = B.3
symbol ANT5 = B.4
symbol ANT6 = B.5

; Temporary storage for the decimal values of the eleven ASCII numbers (0-9) and
; calculations:
symbol X1 = b0
symbol X10 = b1
symbol X100 = b2
symbol K = b3
symbol K10 = b4
symbol K100 = b5
symbol M = b6
symbol M10 = b7
symbol M100 = b8
symbol G = b9
symbol G10 = b10
symbol MHz = b11

main:

; Input VFO A frequency and save decimal values of the eleven ASCII numbers (0-9).
SERRXD ("F","A"),#G10,#G,#M100,#M10,#M,#K100,#K10,#K,#X100,#X10,#X1

; Test to see if anything is stored. The specified antenna LED will light if so.
if G10 <> 0 then high ANT2 else low ANT2 endif
if G <> 0 then high ANT3 else low ANT3 endif
if M100 <> 0 then high ANT4 else low ANT4 endif
If M10 <> 0 then high ANT5 else low ANT5 endif
if M <> 0 then high ANT6 else low ANT6 endif
goto main

What puzzles me is that if I substitute = for <>. I get the same result, no LEDs light. This does't make any sense. For example, how can G10 both = zero and <> 0 ?

Am I specifying "FA" correctly? Should it be "F","A" or "FA"?
 

inglewoodpete

Senior Member
You should specify "FA" as a string. Also, temporarily add a SerTxd (or an LED flash) immediately after the SerRxd to ensure that execution is getting past the receive command.

Edit: are you sending the data in at the correct baud rate for the PICAXE model and clock speed?
 
Last edited:

jehill39

Active member
inglewoodpete: Thanks for confirming that "FA" is correct. I added the line "high AN2" immediately following the SERRXD command and as you may have suspected, it didn't execute, meaning that the specified data is not being received.

Although the utility that I am using properly displays VFO A frequency, it appears that it is not transmitting data to the PICAXE port. I have already requested the the author determine if that is the case. Meanwhile, I should be able to get past the SERRCD command by manually sending the required stream in the PICAXE editor.
 

hippy

Technical Support
Staff member
; Input VFO A frequency and save decimal values of the eleven ASCII numbers (0-9).
SERRXD ("F","A"),#G10,#G,#M100,#M10,#M,#K100,#K10,#K,#X100,#X10,#X1
You don't want those # symbols there if receiving ASCII digits into each. and you will have to subtract "0" or $30 to get those ASCII characters to be numeric 0-9 after reception.

"FA" and "F","A" are interpreted the same way, so it doesn't matter how you specify them.

Try a simple Proof of Concept ...
Code:
Symbol G   = b9
Symbol G10 = b10

Do
  SerRxd ("FA"),G10,G
  G10 = G10 - "0"
  G   = G   - "0"
  w0 = G10 * 10 + G
  SerTxd( "You entered ", #w0, CR, LF )
Loop
You can run that in the simulator. In the terminal, ASCII mode, just enter FA23, press send, and similar.
 

jehill39

Active member
Here's a surprise. If I manually enter FA00014000000; in the terminal (14 MHz), I still don't get to the next line of code.
 

inglewoodpete

Senior Member
Here's a few ideas that should help in diagnosing the problem.

1. Connect the VFO serial ASCII feed via your programming lead to the PICAXE Programming Editor's terminal. This will determine what data is being sent by the VFO and what baud rate it is being sent at.
2. As per hippy's suggestion above, temporarily reduce the receive buffer and/or qualifier.

Is there a reason why you are using SerRxd rather than SerIn? SerIn is more flexible to use. It is possible that the polarity of the data stream is the opposite to what is being expected. SerIn can read True or Inverted data. Alternatively, a 1-transistor inverted can be used. To determine the polarity of the VFO's data stream check it with a multimeter. "True" data idles high, while 'Inverted' data idles low.
 
Last edited:

hippy

Technical Support
Staff member
Here's a surprise. If I manually enter FA00014000000; in the terminal (14 MHz), I still don't get to the next line of code.
Perhaps post your full code. This works for me when I test it in the simulator -
Code:
symbol X1 = b0
symbol X10 = b1
symbol X100 = b2
symbol K = b3
symbol K10 = b4
symbol K100 = b5
symbol M = b6
symbol M10 = b7
symbol M100 = b8
symbol G = b9
symbol G10 = b10
symbol MHz = b11

main:
  SERRXD ("FA"),G10,G,M100,M10,M,K100,K10,K,X100,X10,X1
  G10  = G10  - "0"
  G    = G    - "0"
  M100 = M100 - "0"
  M10  = M10  - "0"
  M    = M    - "0"
  K100 = K100 - "0"
  K10  = K10  - "0"
  K    = K    - "0"
  X100 = X100 - "0"
  X10  = X10  - "0"
  X1   = X1   - "0"
  SERTXD( "You entered ",#G10,#G,#M100,#M10,#M,#K100,#K10,#K,#X100,#X10,#X1, " Hz", CR, LF )
  Goto main
 

Aries

New Member
Here's a surprise. If I manually enter FA00014000000; in the terminal (14 MHz), I still don't get to the next line of code.
which still suggests you are never receiving the "FA". Run it without the FA qualifier, but with a couple of extra variables to receive where the qualifier would normally be, and then use sertxd to print out all the bytes received
 

jehill39

Active member
Thanks for all of your suggestions!

hippy: I loaded your code and it works fine. Here are shots of the PICAXE Terminal window before and after I manually entered a frequency:

1544387511678.png

1544387612414.png

Thank you so much for your effort. Now all I have to do is integrate your code into mine.
 

jehill39

Active member
Let's go back a bit. My comments are in bold within your text.

Here's a few ideas that should help in diagnosing the problem.

1. Connect the VFO serial ASCII feed via your programming lead to the PICAXE Programming Editor's terminal.
I have no way of doing that. All that I can do is specify which port I wan to connect the VFO serial ASCII feed to. I can either connect the feed to my PICAXE 14M2 or connect the PICAXE editor to my PICAXE 14M2. This will determine what data is being sent by the VFO and what baud rate it is being sent at.
2. As per hippy's suggestion above, temporarily reduce the receive buffer and/or qualifier. Actually, I only need the first six digits for my app, so I could eliminate the last five.

Is there a reason why you are using SerRxd rather than SerIn? SerIn is more flexible to use. It is possible that the polarity of the data stream is the opposite to what is being expected. SerIn can read True or Inverted data. Alternatively, a 1-transistor inverted can be used. To determine the polarity of the VFO's data stream check it with a multimeter. "True" data idles high, while 'Inverted' data idles low.
Space is at a premium. A design goal was to make the circuit boards as small as possible to ensure that they fit within the MFJ-4716RC box. See the attached photos to understand the challenge. The LED Display board is buried under the jumpers at the top. The 5VDC power supply is at the bottom.

If you look closely at the bottom photo, you will notice that I removed the PICAXE cable jack and replaced it with headers. I had to chop off the plug to determine which wires to connect to. I turns out that only three wires are connected to the plug:

TX: yellow, RX: orange and GND: black. Notice that I routed the PICAXE cable through an existing hole, soldered solid wires to each wire and plugged them into the appropriate header. I had to do this anyway in order to get the board in the box. A fringe benefit is that I can now at least measure the RX voltage.

The initial value with the PICAXE Editor connected is 0.6 mV. The burst to send a manual command is too short to obtain MAX and MIN values. The MAX and MIN values of the VFO data stream are 330.5 mV and 66.4 mV, respectively. My PICAXE 14M2 doesn't response to the data stream. I sure wish that I had an oscilloscope!
 

Attachments

inglewoodpete

Senior Member
Thanks for the update. It is not clear to me if you have got your project working properly yet.

You may have misunderstood my point about the polarity of the serial data stream from the VFO. I was asking whether the serial data line from the VFO idles low or high (ie when no data is being sent by the VFO). From the voltage values that you provide, it appears that the VFO output serial line idles low. The attached image is an example of two serial data streams that idle low.
~Good~MessageAndEcho.PNG

My understanding is that the PICAXE programming lead uses individual header pin/sockets to connect to your circuit in the box. Is it possible to temporarily pull the receive leg of the programming lead (Ie data ---> computer) and, using a clip lead, connect it to the VFO's serial output? That way you could use the PE Terminal window to see what data is actually being sent by the VFO.
 

jehill39

Active member
I have injected my comments in bold below:

Thanks for the update. It is not clear to me if you have got your project working properly yet. I put the final touches on my program today and tested it. It works beautifully in response to PICAXE Editor Terminal commands. I have attached a copy for your convenience. Unfortunately, I get no response when I connect the PICAXE port to my VFO A source.

You may have misunderstood my point about the polarity of the serial data stream from the VFO. I was asking whether the serial data line from the VFO idles low or high (ie when no data is being sent by the VFO). I can't check this because there is signal the instant that the source is connected. From the voltage values that you provide, it appears that the VFO output serial line idles low. The attached image is an example of two serial data streams that idle low. Those images make it clear what you are taling about.
View attachment 22585

My understanding is that the PICAXE programming lead uses individual header pin/sockets to connect to your circuit in the box. Is it possible to temporarily pull the receive leg of the programming lead (Ie data ---> computer) and, using a clip lead, connect it to the VFO's serial output? That way you could use the PE Terminal window to see what data is actually being sent by the VFO. That's not possible as both the TX and RX terminals are always connected to the same source. In my case, either the PICAXE editor or the VFO A source.
I will install an inverter as soon as I get a chance and see what the effect is. Hopefully, it will solve the problem. However, I have also asked the VFO A source vender if he can add an option to change the polarity. Otherwise, I would have to remove the inverter if a program revision is required.
 

Attachments

inglewoodpete

Senior Member
You could try replacing your SerRxd comment with an equivalent SerIn but with polarity inversion. This will eliminate the need for a hardware inverter. When you use a SerIn on pin C.5, you need to disable automatic download checking, so you will need to add a Disconnect command before the main loop. Note that this will result in downloading new code being more difficult, requiring a hard reset. Refer here to learn about hard resets for downloads.

Code:
 'SERRXD [5000,deselect],("FA"),G10,G,M100,M10,M,K100
  SerIn [5000,deselect],C.5,N4800_4,("FA"),G10,G,M100,M10,M,K100
 

hippy

Technical Support
Staff member
It seems there could be two issues at play; the polarity of the signal being monitored and the ability of a SERRXD or SERIN to keep up with the data being sent.

If the first is a problem then that should be be resolved by using a SERIN command with a T4800 baud rate or by electrically inverting the signal and using SERRXD.

If the second is a problem that might be resolved by increasing the operating speed of the PICAXE by using a SETFREQ command and using an appropriate T4800_nn or N4800_nn baud rate.

It would be best to configure the system so the PICAXE reads the VFO data on a SERIN pin and keep the SERRXD and SERTXD pins free for downloading code and monitoring what the PICAXE is doing or receiving.

It may also be best to prototype the circuit outside the VFO with longer wires and then shorten those and move the PICAXE into the VCO box when the project is working.

I would start with something like below, with VCO_RX_PIN adjusted as appropriate, which will report any data received straight to the Terminal screen once downloaded -
Code:
#Picaxe 14M2
#Terminal 19200
#No_Data

Symbol PICAXE_FREQ = M32

Symbol VCO_RX_PIN  = C.0
Symbol VCO_RX_BAUD = N4800_32

Symbol PC_TX_BAUD  = B19200_32

SetFreq PICAXE_FREQ
HSerSetup PC_TX_BAUD, %10010
Pause 16000
HSerOut 0, ( CR, LF, "Started", CR, LF )
Do
  SerIn VCO_RX_PIN, VCO_RX_BAUD, b0
  HSerOut 0,(b0)
Loop
The data reported may not be complete, may not be meaningful, but should give an indication of how the program needs to be altered to make it work.
 
Last edited:

jehill39

Active member
You could try replacing your SerRxd comment with an equivalent SerIn but with polarity inversion. This will eliminate the need for a hardware inverter. When you use a SerIn on pin C.5, you need to disable automatic download checking, so you will need to add a Disconnect command before the main loop. Note that this will result in downloading new code being more difficult, requiring a hard reset. Refer here to learn about hard resets for downloads.

Code:
 'SERRXD [5000,deselect],("FA"),G10,G,M100,M10,M,K100
  SerIn [5000,deselect],C.5,N4800_4,("FA"),G10,G,M100,M10,M,K100
According to the manual:

"The serin command is used to receive serial data into an input pin of the
microcontroller. It cannot be used with the serial download input pin, which
requires use of the serrxd command instead."

It wouldn't be too much trouble to connect a wire to one of the unused inputs of the 14M2 and connect it to the existing RX input. However, I have been thinking of redoing the wiring to the RX, TX and GND pins anyway, so I could easily add an inverter at that time, as I have a handful of 2N7000 FET switches.
 

jehill39

Active member
It seems there could be two issues at play; the polarity of the signal being monitored and the ability of a SERRXD or SERIN to keep up with the data being sent.

If the first is a problem then that should be be resolved by using a SERIN command with a T4800 baud rate or by electrically inverting the signal and using SERRXD.

If the second is a problem that might be resolved by increasing the operating speed of the PICAXE by using a SETFREQ command and using an appropriate T4800_nn or N4800_nn baud rate.

It would be best to configure the system so the PICAXE reads the VFO data on a SERIN pin and keep the SERRXD and SERTXD pins free for downloading code and monitoring what the PICAXE is doing or receiving.

It may also be best to prototype the circuit outside the VFO with longer wires and then shorten those and move the PICAXE into the VCO box when the project is working.

I would start with something like below, with VCO_RX_PIN adjusted as appropriate, which will report any data received straight to the Terminal screen once downloaded -
Code:
#Picaxe 14M2
#Terminal 19200
#No_Data

Symbol PICAXE_FREQ = M32

Symbol VCO_RX_PIN  = C.0
Symbol VCO_RX_BAUD = N4800_32

Symbol PC_TX_BAUD  = B19200_32

SetFreq PICAXE_FREQ
HSerSetup PC_TX_BAUD, %10010
Pause 16000
HSerOut 0, ( CR, LF, "Started", CR, LF )
Do
  SerIn VCO_RX_PIN, VCO_RX_BAUD, b0
  HSerOut 0,(b0)
Loop
The data reported may not be complete, may not be meaningful, but should give an indication of how the program needs to be altered to make it work.
It is clear that I would need to solder a wire to the C.0 pin to do your testing. Would it be ok to solder the other end to pin C.5 to take advantage of the existing input resistors?

Now I see why both of you suggest either using an inverter or the the Serin command. According to the manual:

"When using simple resistor interface, use N (inverted) signals. When using a MAX232 type interface use T (true) signals."

In other words, the RX input normally needs to be inverted. I suspect that the PICAXE Editor accounts for this by inverting the sent data. This is all the more reason for installing an inverter to see if it solves the problem.
 

hippy

Technical Support
Staff member
"The serin command is used to receive serial data into an input pin of the microcontroller. It cannot be used with the serial download input pin, which requires use of the serrxd command instead."
That only applies to those PICAXE chips which don't have a port.pin designation for the serial download input pin.

The online command documentation doesn't reflect that either so I have filed an update request to have that made clearer.

It wouldn't be too much trouble to connect a wire to one of the unused inputs of the 14M2 and connect it to the existing RX input
That would also work. You would however have to use the DISCONNECT command to prevent reset issues.
 

jehill39

Active member
You may have misunderstood my point about the polarity of the serial data stream from the VFO. I was asking whether the serial data line from the VFO idles low or high (ie when no data is being sent by the VFO). From the voltage values that you provide, it appears that the VFO output serial line idles low. The attached image is an example of two serial data streams that idle low.
View attachment 22585
Is the vertical scale set to 2V/cm on your screen shots or something else?
 

jehill39

Active member
That only applies to those PICAXE chips which don't have a port.pin designation for the serial download input pin.

The online command documentation doesn't reflect that either so I have filed an update request to have that made clearer.
The significance of this comment didn't register until after I had tried it and also installed an inverter. Neither method solved the problem. FWIW, the MIN and MAX values for the normal connection were 0.208 V and 0.053 V, respectively. The same values with the inverter were 4.50 V and 4.16 V, respectively. I suspect that since these voltages were measured on DC volts, these numbers are really averages.

Anyway, I have studied the code that you offered and think that I understand it. To get the C.0 input needed, should simply add a jumper between pins C.0 and C.5 or should I add another 22K resistor and tie it to the same point as the present 22K resistor?

In order to see the terminal's response to the PC input, I have ordered another AXE027 cable. By connecting TX to RX and RX to TX, I will effectively have a USB to USB crossover cable.

An alternate approach:

The RCForb server that I am using to provide remote control of a transceiver offers a VCOM port that may be used to communicate with the transceiver locally. Is there a way that I can connect my PICAXE port to that port? If there is, I can ask for the VFO A frequency directly with a simple FA; command. I have tried that using the PICAXE terminal and it works fine.
 

inglewoodpete

Senior Member
Is the vertical scale set to 2V/cm on your screen shots or something else?
From memory, that screen snip was from a project using 5v for both the microcontroller and peripheral. So, the vertical axis would be showing 2v / unit.

Average voltages measured from the serial data lines are not particularly useful, apart from indicating the polarity of the data line. So this shows the VFO output idles low and the inverter, well, inverts it;).

hippy's test code, posted in #15 could be a useful stepping stone to resolving what data is being transmitted.
 
Last edited:

jehill39

Active member
Before I do that, I'm going to configure my program for 9600 baud operation. The reason for trying that is that is the the utility that I am using to read VFO A was originally designed for 9600 baud. On my request, an option to select the desired baud rate was added by someone other than the original author. I am thinking that there is a chance that the utility continues to obtain data from the transceiver at 9600 baud, but sends it to the PICAXE port at 4800 baud, my selected baud rate. That would make a mess of things for sure.
 

inglewoodpete

Senior Member
Using 9600 baud may actually work against you. One of the problems with SerRxd (and SerIn) is that the handlers do not utilise a hardware UART. These commands use a bit-banging method to receive and store each character. If the serial data arrives too fast (or there is insufficient time between each arriving character) the start bit of successive characters can get missed, resulting in corrupted data.
 
Last edited:

jehill39

Active member
Using 9600 baud may actually work against you. One of the problems with SerRxd (and SerIn) is that the handlers do not utilise a hardware UART. These commands use a bit-banging method to receive and store each character. If the serial data arrives too fast (or there is insufficient time between each arriving character) the start bit of successive characters can get missed, resulting in corrupted data.
PROBLEM SOLVED! That was the hint that I needed! I restored the command that you suggested earlier, switched to T1200_4 and reduced the source speed to 1200 baud. It didn't work. I then switched to N1200_4 and it worked! Finally, I switched to N2400_4 and it still worked, so that'ts where I left it. So, the current command is as follows:

SerIn [5000,deselect],C.5,N2400_4,("FA"),G10,G,M100,M10,M,K100

So now I am ready to show my superiors the final product. I don't know how I would have completed it without your help (both of you).
 
Top