How do you operate an 08M2 at 9600 baud?

#1
I am doing something wrong with the serout command. I want to use a device (Atlas Scientific EZO ORP) that communicates with 5v RS232 protocol. Its default baud rate is 9600. The device allows the user to change this rate to a number of other rates but first the change command has to be sent at 9600 baud.
I am using an 08M2 and I tried this snippet of code to start the process:

#picaxe 08m2
#no_data

symbol Txin = 3
symbol Rxout = 4

setfreq m16
serout Rxout,T9600,("baud",1200,cr) 'sends baud rate to EZO
serout Rxout,T1200,("baud,?",cr) 'requests what the baud rate is
serin[1000],Txin,T1200,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9
'expected answer ?Baud,1200
Debug

The F4 key comes up with an error message ‘unknown symbol – T9600
If I change T9600 to T4800 everything is good.
The manual states that the serout command can run at 9600 baud if the 08M2 is overclocked. What am I doing wrong?
 

PhilHornby

Senior Member
#2
Is this the datasheet for the device https://www.atlas-scientific.com/_files/_datasheets/_circuit/ORP_EZO_datasheet.pdf ?

A number of observations :-

Your definitions of Txin and Rxout should be in the form "C.n", where n is the pin (e.g C.1, C.2 etc) - for clarity, if nothing else. The format you have used is presumably interpreted as something, but I wouldn't like to predict what (I believe the old 08M used this style).

Why not use m32, rather than m16? .. Speed is always of the essence, with serial comms. (m16 might use less power than m32)

Before the first serout statement, issue a High Rxout. This presets the line logic level, rather than waiting for the 1st serout to do it. The serout will do it - but at the expense of the 1st bit of the 1st byte being lost.

I think there's a misplaced quotation mark in this statement: serout Rxout,T9600,("baud",1200,cr) 'sends baud rate to EZO
From the datasheet, serout Rxout,T9600,("baud,1200",cr) 'sends baud rate to EZO looks more likely!

The next potential issue, is a short-coming of the "M2" series...

...it is entirely possible that the "EZO ORP" starts to send it's reponse, before the Picaxe manages to issue the serin statement. If this happens, characters will be lost - there is no background buffering. Whether this is the case, is luck of the draw: it happens with an ELM327 OBD interface, but it doesn't happen with a HC-12 radio.

The EZO ORP appears to support I2C ... as does the 08M2 - so you could use that instead.

EDIT

I missed the actual question - and answered some that you didn't ask instead :)

If you swap T9600 for T9600_16, the Picaxe Editor should be happy with it. (You'll have to lower the Picaxe speed to 8MHz or lower to use 1200 baud)
 
Last edited:
#4
Thank you! The fix was 9600_32, I took your advise on m32. I also have fixed some of the odds and ends you found. I will not be able to try the system until tomorrow.
I am a hardware engineer, software comes hard to me.
 
Top