Communication to a pressure/temperature sensor via serial

golfdude

New Member
I am looking for help on a serial communication problem / project. I want to communicate with a pressure/temperature sensor. The sensor has a input line, output line and a clock line. I was going to pulse an output to give me the serial clock and then send and receive data via the other two lines. Is it possible to use an embedded comand instead of hard coding the communication?
 

Chavaquiah

Senior Member
Hello and welcome to the Picaxe forum.

It sounds like your sensor may use some form of SPI communications. If so and if you have a compatible Picaxe model, there are good chances you can use SPIIN/SPIOUT or even their hardware equivalents.

However, it is impossible to really answer without knowing both the sensor and the Picaxe chip in use. Could you please provide a link to a data sheet (for the sensor) and identify the Picaxe?
 

hippy

Ex-Staff (retired)
That looks like SPI control so provide a 32.768kHz clock ( possibly using PWMOUT ) then simply clock the data in and out. There are diagrams from page 14 onwards showing what you need to do and a AN510 which explains it in greater detail.
 

Chavaquiah

Senior Member
Oh, it seems the 18M2 does not have a hardware SPI unit. You can't use spiin and spiout but will have to, instead, use the routines provided in the manual.

Please see pages 212 to 216 of the Picaxe's Manual 2.

By the way, this thread was created in the finished projects section. Obviously, your project is not quite complete so the Active Picaxe Forum section would be the right place. Not to worry, as I'm sure a moderator will soon move the thread to the right section.
 

golfdude

New Member
Thanks for the help, I have now written the program + simulated it and it all seems to work on the screen ok. I am using a PICAXE Connect board (AXE210) with an XBee module and I wanted to make sure that I assign the input and output pins correctly. The program in the manual says to use input 7 but I cannot work out where that is on the 18M2 chip, ie which pin. I want to use pin 17 (C.0) but when I try to specify this in the program then I get a syntax error. I tried the following:-

symbol serdata = input C.0

Can anybody help please?
 

hippy

Ex-Staff (retired)
You will want one of the following depending on how "serdata" is used in your program -

Symbol serdata = C.0
Symbol serdata = pinC.0
 

golfdude

New Member
My code is attached. The manual states that I need to specify that serdata is an input so would your suggestions work or do I need add more code to tell the Pic that the pin is an input?
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
That code with "Symbol serdata = C.0" gives a syntax error in -

if serdata = 0 then skipMSBPost

So that seemingly rules out "Symbol serdata = C.0", leaving you with "Symbol serdata = pinC.0", which compiles without error.

From the other direction the "if serdata =" requires a variable and "pinC.0" is a variable ( contains what level the pin is at ) whereas "C.0" is a pin identifier, effectively 'just a number', and not a variable.

By default the C.0 pin is an input so you don't need to do anything to make that an input, unless you elsewhere make it an output.
 

yaquaholic

New Member
Golfdude:
I'm trying to acheive something very similar, except with a MEAS MS5541-30C pressure/temp sensor.
Did you get it working?
Would be kind enough to share your discoveries and pit-falls with me please?

Thanks :)
 

geoff07

Senior Member
It depends a lot on what your comms method is, but if you want to use serial comms you might get something from my system, post 16652. I send four temperatures by serial comms to a central controller. The signals are sent at 4800 baud by four 08Ms, one controlling each sensor. Signals are sent at different prime number intervals (seconds) from each chip to minimise clashing, and are diode multiplexed on receipt, causing an interrupt that reads the packet. Clashes are no more than 2-3% (measured), and it is very reliable.

I had to cover reasonable distances and use existing cabling, but radio would work too.

If your sensors can give up their secrets to an 08M this might help you.
 
Top