PropBasic and One-wire
Discovery
Posts: 606
in Propeller 1
Hi Bean,
I am struggling with the load library instructions as they pertain to One-wire Read and Write.
I have serial numbers of the one-wire devices I will use so I don't need code for reading the serial numbers.
Could you supply code for writing PropBasic instructions that set the four digital outputs of the DS2450, read the four analog inputs of the DS2450, and read the temperature of the DS1820?
Sincerely,
Discovery
I am struggling with the load library instructions as they pertain to One-wire Read and Write.
I have serial numbers of the one-wire devices I will use so I don't need code for reading the serial numbers.
Could you supply code for writing PropBasic instructions that set the four digital outputs of the DS2450, read the four analog inputs of the DS2450, and read the temperature of the DS1820?
Sincerely,
Discovery
Comments
Discovery
'{$STAMP BS2p}
'One-Wire serial communications to the DS18S20
'I/O Definitions
DQ PIN 0
'Constants
RdROM CON $33
SkipROM CON $CC
Cvrt Tmp CON $44
RdSP CON $BE
'Variables
romData VAR Byte(8)
tempIn VAR Word
sign VAR tempIn.BIT8
tLo VAR tempIn.LOWBYTE
tHi VAR tempIn.HIGHBYTE
tSign VAR Bit
tempC VAR Word
tempF VAR Word
Main:
DO
OWOUT DQ, 1, [rdROM]
OWIN DQ, 2, [STR romData\8]
GOSUB Get_Temperature
DEBUG HOME,
"SD18S20",CR,
"_________",CR,
SDEC tempC, " C ",CR,
SDEC tempF, " F "
PAUSE 500
LOOP
END
Get_Temperature:
OWOUT DQ, 1, [SkipROM, CvrtTmp] 'Start conversion
PAUSE 500
OWOUT DQ, 1, [SkipROM, RdSP]
OWIN DQ, 2, [tLo, tHi] 'Read temperature
tSign = sign 'Save the sign bit
tempIn = tempIn/2 'Round to whole bit
IF tSign = 0 THEN NoNeg1
tempIn = tempIn | $FF00 'Extend sign bits for negs
NoNeg1:
tempC = tempIn 'Save Celcius value
tempIn = tempIn */ $01CC 'Multiply bu 1.8
IF tSign = 0 THEN NoNeg2 'If negative, extend sign bit
tempIn = tempIn | $FF00
NoNeg2:
tempF = tempIn + 32 'Finish C to F conversion
RETURN
Sincerely,
Discovery
Or, is there anyone with the where-with-all to write the one-wire Propeller Basic code?
Sincerely,
Discovery
PS This is really important!
I don't know if there's any existing PropBasic code for that. Have you looked in the Obex for Spin objects that access that hardware? If there are some, then I can see 3 solutions for you:
(1) Port the Spin code to PropBasic. This will require a bit of work, but would have the big advantage that (if you share the code) other PropBasic users will be able to use the libraries.
(2) Port your code to Spin. How easy/hard this will be depends on your code, of course, but Spin isn't too hard to learn. The advantage here is that Spin is widely used and supported on the Propeller.
(3) Port your code to Fastspin/BASIC, and use the Spin objects directly from Basic. Fastspin/BASIC is a bit different in syntax from PropBasic, so this would be work, but if your code isn't too large it might be easier than option (1).
My PropBasic directory from Bean has a directory called "demos"
in there is a file DS18B20.pbas
at the top of this document it says
Dave
How do I access your PropBasic directory?
Discovery
How did that happen?
Glad you caught it.
Dave
A third post was started about the same topic which is against forum rules. It was deleted.
I am aware that you blocked my attempts to reach Bean by invoking the redundancy rule. In the beginning, Bean said that he would help as I learn PropBasic since I wanted to convert my industrial control system from BS2 controllers to Propeller controllers using PropBasic exclusively. The first of two control boards was successfully converted to a Propeller using Bean's help. He supplied the Real-Time clock PropBasic code that ran on a COG but the clock ran too fast. It was the brilliance of ersmith who realized that the WAIT addr instruction could be used to adjust the rate. Smith was absolutely correct and I was able to increase the 80_000_000 value to 80_000_700 and trim the clock to be highly accurate. The combination of Bean and ersmith solved the problem that I had no clue how to solve. I was hoping to contact Bean for help in using the Propeller one-wire commands since my system uses one of two one-wire coax lines to read my system sensors and a second one-wire coax line to control devices in the factory which include motors, heaters, etc. I tried to use the information in the PropBasic one-wire library to read temperature of a single DS18S20 using my Propeller Activity Board but everything I tried produced an error "Insufficient Number of Parameters" but as far as I can tell no additional parameters are needed for the OW-READ instruction. But things get more difficult when I need to communicate with several DS2450 Quad A/D Converter/Quad Digital Output devices that are used extensively in my system. The BS2 code is used for communication with the DS2450s and sends instructions to the chip for configuring the device to be a quad ADC or a quad DO. This code was supplied by a forum member and it works perfectly with the exception that DS2450 can only convert 8 bits and no more. The specification states that 16 bits are possible. I apologize for trying to open another forum discussion with Bean but it appears that Bean is too busy and just maybe he could provide a spark that ersmith or someone else could follow to generate the PropBasic code that I need to make the conversion.
Discovery
http://forums.parallax.com/discussion/169488/propbasic-and-one-wire#latest
Instructions on PM:
http://forums.parallax.com/discussion/161418/how-to-sending-a-pm#latest
Tritonium,
I downloaded the demo code and installed it in my program. It compiled and executed but I have no way of knowing if it reads the DS18S20 since the temperature message is output using SEROUT TX, Baud, Message and I do not have the TX Pin connected to my PC. I don't know how to do that.
Secondly, my system uses six DS18S20 temperature sensors...how do I individually address each sensor?
Finally, can the variable "value" be used in an IF statement to determine if the value is between 10 and 30 if in Celsius units?
Would you have the time to look into devising the PropBasic code for reading and writing data to the DS2450 quad ADC/DO?
Sincerely,
Discovery
Discovery
The demo program appears to read the DS18S20 as long as I divide the numerical in "value" by 10.
So a value of 205 is actually reading a temperature of 20.5C and this value changes as I increase or decrease the temperature of the sensor. This is good.
Discovery
Way back when I was working with the initial development of the BS2 software shown above. Sending control data to the DS18S20 using the PropBasic commands: OWWRITE, OWREAD, OWRESET, with the additional parameters attached appears to be far simpler than the BS2 commands.
Now I will configure a DS2450S and attach it to the Propeller One-wire and try to send and receive data from its registers.
Discovery
OWRESET DQPin
PAUSE 750
OWWRITE DQPin, $44CC\16 'SKIP & CONVERT
OWRESET DQPin
PAUSE 750
OWWRITE DQPin, $BECC\16 'SKIP & READ SCRATCH PAD
OWREAD DQPin, value\16 'READ THE TEMPERATURE
I want to read multiple devices on the one-wire using the Match instruction $55.
I tried the following code but got an error "INVALID INTEGER" at compile time.
OWRESET DQPin
PAUSE 750
OWWRITE DQPin, $4410848293020800D555\80 'MATCH 64 bit serial number & CONVERT
OWRESET DQPin
PAUSE 750
OWWRITE DQPin, $BE10848293020800D555\80 'MATCH 64 bit serial number & READ SCRATCH PAD
OWREAD DQPin, value\16 'READ THE TEMPERATURE
$55 is the Match Instruction
$10848293020800D55 IS THE 64 BIT serial number
$BE is the Read Scratch Pad Instruction
What is the correct way to match the serial number of one-wire devices?
Sincerely,
Discovery
Discovery
Show me the PropBasic code you wrote and used to match the serial number of a DS18S20 temperature sensor.
Discovery
You also have a fundamental misunderstanding about PropBasic: the error message is referring to that 80-bit number that you're trying to send. The largest integer PropBasic can handle is 32 bits, thus the "invalid integer" error. Break that huge number into smaller parts and send them separately, adjusting the "number of bits" in the OWWRITE command as needed. For clarity, I'd break them up logically, i.e. send the command byte, then the serial number in smaller pieces, etc. If you follow the sequence in the datasheet, and don't try to send something larger than PropBasic can deal with, you should have better luck. You should also read the entire section of the datasheet (1-wire bus system) that preceeds the example.
And please don't ask me to offer code, because I haven't written any for what you are trying to do. I'm just trying to point you in the right direction.
If you spend a bit of time with the suggested documentation it should make sense.
Discovery
OWWRITE DQPin, $0800D555\32
OWWRITE DQPin, $829302\24
OWWRITE DQPin, $441084\24
The 80-bit string for reading the scratch pad was recomposed into two 24-bit strings and one 32-bit string as shown below.
OWWRITE DQPin, $0800D555\32
OWWRITE DQPin, $829302\24
OWWRITE DQPin, $BE1084\24
This code compiled without errors; however the program downloaded into the Propeller did not read the temperature...most likely it did not find a match.
Could the sequence of bits in the serial number be in error? I will try reversing the bits.
Discovery
OWWRITE DQPin, $0800D555\32
OWWRITE DQPin, $829302\24
OWWRITE DQPin, $441084\24
The 80-bit string for reading the scratch pad was recomposed into two 24-bit strings and one 32-bit string as shown below.
OWWRITE DQPin, $0800D555\32
OWWRITE DQPin, $829302\24
OWWRITE DQPin, $BE1084\24
This code compiled without errors; however the program downloaded into the Propeller did not read the temperature.
Discovery
The program compiled without errors but the Propeller could not match the ID.
I reversed the ID bits in the 16-bit segments and the Propeller could not make a match.
To verify the program I used the skip command and the Propeller converted the temperature reading just fine.
I don't know what to try next.
Discovery
-- OW_RESET
-- OW_WR_BYTE
-- OW_RD_BYTE
-- OW_RD_BIT
The PropBasic code used in the above program that reads the DS18S20 using the skip ($CC) instruction and the convert ($44) work perfectly and they are sent as two byte pairs \16 equivalent to a word.
OWWRITE DQPin, $44CC\16
OWWRITE DQPin, $BECC\16
Some time ago I asked for a PropBasic program to read the DS18S20 and one was supplied by a forum member. It did not work, so I added a PAUSE 750 instruction after the OWRESET DQPin instruction and that did the trick. I wonder if some other step needs to be inserted to make the MATCH instruction work.
Any ideas?
Sincerely,
Discovery