RS232 Communications problem

1968neil

Senior Member
Hi Chaps,
I'm having a problem with controlling a bench psu via RS232.
If i send the command OUTPut 1 from terminal it works perfectly

If i send exactly the same from my 18M2 via a MAX232 it does nothing, i can see data but the data length looks to be much longer than the terminal version on the oscilloscope.
I've tried to keep it as simple as possible to get the basics working, can anyone enlighten me as to what i may not be doing quite right ?

Code :

Symbol Baud = T9600_8 ; Set Baud rate T9600
Symbol RS232RX = B.4 ; Define RS232 Receive Pin
Symbol RS232TX = B.5 ; Define RS232 Transmit Pin

High RS232TX
Pause 2000

MAIN:

Serout RS232TX,Baud,("OUTPut 1") ; Turn on psu
Pause 2000
Serout RS232TX,Baud,("OUTPut 0") ; Turn Off Psu
Pause 2000
Goto Main
 
....i can see data but the data length looks to be much longer than the terminal version on the oscilloscope.
I've tried to keep it as simple as possible to get the basics working, can anyone enlighten me as to what i may not be doing quite right ?
If you're using an oscilloscope, measure the length (Ie timing) of a single bit. Baudrate = 1/Time

If the baud rate is within a few percent of the correct speed, your power supply may require strict timing of each character string. SerOut inserts a short pause between each character (so that another PICAXE process/save each character received using their SerIn command). If that is the case, you may have more success with hSerOut.
 
I'm with Engle ... the M2 parts default to 4MHZ ... so you should explicitly call out "setfreq m8" to get it up to 8MHZ ...

If it's running at 4MHZ, but you've configured an 8MHZ baud rate ... the *actual* baud-rate is probably 4800 bps.
 
Ok, I have set the psu to 4800 baud to slow things down a little.
I have tried all of the above suggestions and no change, Just for good measure i have kept everything set to a standard M2 4mhz.
No CR or LF required
The power supply manual says its a simple RS232 No parity, 8 databits and 0 stop.

Current code used =

[setfreq m4

Symbol RS232RX = B.4 ; Define RS232 Receive Pin
Symbol RS232TX = B.5 ; Define RS232 Transmit Pin
Symbol Baud = T4800_4
High RS232TX
Pause 2000

MAIN:

serout RS232TX,Baud,("OUTPut 1") ; transmit value to PSU
Pause 2000
serout RS232TX,Baud,("OUTPut 0") ; transmit value to PSU
Pause 2000
Goto Main]

I've attached an image from my scope
How can something so straightforward be such a pain in the backside !
Thanks for any suggestions in advance.
 

Attachments

  • Scope.jpg
    Scope.jpg
    386.1 KB · Views: 9
Please post an image from your scope (Including all the settings) for

1: a successful transaction from your PC tot he PSU
2: an unsuccessful transaction from the 18M2 to the PSU

Thanks!
 
The levels and rate look OK to me, if that's 10V/div and 1ms/div. The bytes shown also seem to be "OU".

It's common to end in CR LF, have you checked the terminal settings to see these aren't being added automatically?

Back to your last comment and ingelwoodpete's: there appears to be about 3 bit times between the last bit of data and the next start bit. With hserout you'll have 1 stop bit and if the PSU insists on none then you're in bit-bang territory.

With bpowell it would help to see a comparison trace of the working terminal :) If you're using the PE Terminal with the working connection then it's probably going to have more than 10ms gap between bytes, which is completely opposite to no stop bits. You could emulate that with pause statements between each character.
 
I have attached images of whats happening, if i look at the data sent from the 18M2 in terminal it appears to be correct.
Sending the OUTPut 1 directly from terminal to the PSU works perfectly as does any request for information from the Psu.

Anything i send that is identical from the picaxe serout or Hserout is ignored by the Psu, all i can think is its a timing issue ?
There seems to be 5 extra pulses that are not on the terminal version ?


Thanks
 

Attachments

  • From Picaxe to PSU.jpg
    From Picaxe to PSU.jpg
    865.2 KB · Views: 8
  • PC to PSU.jpg
    PC to PSU.jpg
    872 KB · Views: 7
The 5 extra pulses are the "U", which is $55 or 0101 0101. It's sent least significant bit first and the high pulses are RS232 zero's, starting with the start bit, so the 5 highs are the start bit and the 4 zeros.

The "U" is just close to the "O", so I suggest you try my idea of pause commands between sending individual characters just as a test, e.g, pause 12. You should try and match the spacing of the good signal if you can but that's off the right of the screen so isn't known.

It could be a rate tolerance problem but IMHO it shouldn't be very likely. I'd try and rule out whether your device just needs time to process each character.
 
Here are a couple of screenshots taken with a logic analyser.
As Engle said, the 5 extra pulses are the character "U" ($55), so they should be there. The main difference between the 2 traces is that the picaxe has about 0.5 ms between each character, whereas the terminal has around 7.3 ms between each character.


This is "OUTPut 1" sent from the Terminal:

ScreenHunter_01 Feb. 19 12.32.jpg



This is "OUTPut 1" sent from a 08M2:

ScreenHunter_02 Feb. 19 12.36.jpg

This is the code I used for testing.

Code:
#picaxe 08m2
#no_data

setfreq m4

Symbol RS232RX = C.1  ' B.4 on 18M2 ; Define RS232 Receive Pin
Symbol RS232TX = C.2  ' B.5 on 18M2 ; Define RS232 Transmit Pin
Symbol Baud = N4800_4
Low RS232TX
Pause 2000

MAIN:
  serout RS232TX,Baud,("OUTPut 1") ; transmit value to PSU
  Pause 2000
  serout RS232TX,Baud,("OUTPut 0") ; transmit value to PSU
  Pause 2000
Goto Main
 
Hi Chaps,
Ive tried the following today using this code which i assume is what you meant ?
Still no change, quite frustrating ......

Code:
Setfreq m4

Symbol RS232RX = B.4    ; Define RS232 Receive Pin
Symbol RS232TX = B.5    ; Define RS232 Transmit Pin
Symbol Baud    = T4800_4
Symbol Interdigit_Delay = 12
High RS232TX
Pause 2000

Main:

Serout RS232TX,Baud,("OUTPut 1")
Pause 2000

Serout RS232TX,Baud,("O"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("U"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("T"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("P"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("u"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("t"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,(" "):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("1"):Pause Interdigit_Delay    ; transmit value to PSU
Pause 2000
Serout RS232TX,Baud,("O"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("U"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("T"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("P"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("u"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("t"):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,(" "):Pause Interdigit_Delay    ; transmit value to PSU
Serout RS232TX,Baud,("0"):Pause Interdigit_Delay    ; transmit value to PSU
Pause 2000
Goto Main
 
Are you absolutely sure that the terminal is not sending a CR and/or LF after each command ?

It is very unusual for a device to work with no CR or LF.

Can you post an analyser trace showing a full "OUTPut 1" message from the terminal ?.
Most analysers will let you format the display as characters instead of bits, which will let you fit more on the screen.

Or, even quicker, add some lines of code to your last post, just before each pause 2000s.

Serout RS232TX,Baud,( Cr ) : Pause Interdigit_Delay ; transmit CR to PSU
Serout RS232TX,Baud,( Lf ) : Pause Interdigit_Delay ; transmit LF to PSU

Cr and Lf are predefined in PE6, Cr is 13 dec or 0D hex, Lf is 10 dec or 0A hex.
 
Most definitely with Buzby on that, as options are running dry.

Perhaps also delete, or comment out, the first line after Main: in case it's hanging the PSU.

And double check the connectors to be sure the PSU is seeing what the scope is seeing.
 
Hi chaps,

Buzby hit the nail on the head (as usual).
I tried CR in the beginning with no success. So wrongly assumed it was a problem.
I’ve tried both now and it’s solved the problem.
It seems that the power supply needs both CR and LF.
The only thing I can take from this is I’ve learned more about RS232 than I knew before 🤦 and it’s amazing how quick you can go down a rabbit hole without realising it.
Once again.. thankyou so much for the invaluable insights and information.
I’m forever appreciative 👍
Regards
Neil
 
Back
Top