1-wire support 20x2

jmumby

Senior Member
1-wire commands (owin owout) can be used from any I/O pin on a 20x2? I see the infamous 'One-Wire Tutorial’ is still AWOL. Just the theory of 1-wire is...well, 1 wire. If I were to use a input and output pin wouldn't that technically make it a 2-wire?
 

hippy

Technical Support
Staff member
Not sure I understand how you are seeing it.

A 1-wire devices requires one control wire which will go to a single I/O pin, that I/O pin must be physically capable of being input and output - even if defined otherwise as 'input only' by the PICAXE I/O configuration, for example 18X can ReadTemp even if the Input Pin cannot be used as an Output Pin under program control.

You don't need to control a 1-wire device using multiple I/O pins on a PICAXE and, even if you did, there would sill only be one control wire needed to the device. Even if you bizarrely used two I/O pins and connected the two wires at the 1-wire device control leg, the leg itself being 'the one wire'. If it's all elasticated wire, you could slide the solder join down the wires, so it's just a topographical issue as to not appearing to be single wire.
 

inglewoodpete

Senior Member
jmumby, Check the command manual. The owin, owout and readtemp commands all refer to an input pin. Take this a step further: pin C.6 on the 20x2 can only be used as an input, so could never receive data (eg a response from the 1-wire device) so could not be used for 1-wire comms.
 

jmumby

Senior Member
jmumby, Check the command manual. The owin, owout and readtemp commands all refer to an input pin. Take this a step further: pin C.6 on the 20x2 can only be used as an input, so could never receive data (eg a response from the 1-wire device) so could not be used for 1-wire comms.
So what your saying is that all 'B.' pins could be used for owin, owout?

Code:
owout pin,mode,(variable,variable...)
- Pin is a variable/constant (0-7) which specifies the [b]input[/b] pin to use.
I guess RTFM does come into it a bit.
 

hippy

Technical Support
Staff member
"Pin number, 0-7", generally refer to the pre-X2 PICAXE's. On the X2's any pin can be used for input or output except those limited by silicon or used for Download Serial In and Serial Out.

On the 20X2 that means you can use one wire commands on any pin B.0 to B.7, C.0 to C.5 and C.7 - pin C.6 is input only because of silicon design.
 

jmumby

Senior Member
Im trying to read the contents of a DS2432. It is write protected so I can't write to it, but I only want to read from it. The function example is below

Code:
+----+-----+-------------------------------------------------+
| Tx |     | (Reset) Reset pulse                             |
| Rx |     | (Presence) Presence pulse                       |
| Tx | CCh | Issue “Skip ROM” command                        |
| Tx | F0h | Issue “Read Memory” command                     |
| Tx | 00h | TA1, beginning offset = 00h                     |
| Tx | 00h | TA2, address = 0000h                            |
| Rx |     | <144 Data Bytes> Read the entire memory         |
| Tx |     | (Reset) Reset pulse                             |
| Rx |     | (Presence) Presence pulse                       |
+----+-----+-------------------------------------------------+
I have formulated the following to get the first 8 bytes

Code:
PAUSE 10
OWOUT 7,%1001,(0xCC,0xF0,0x00,0x00)
FOR B3 = 0 TO 7
  OWIN  7,0,(b0)  ; Read byte
  DEBUG
NEXT B3
Don't seem to be having much joy with this. Look ok to everyone? 1k pullup on the pin
 
Last edited:

hippy

Technical Support
Staff member
I'm not familiar with that or any one-wire device beyond DS18B20 but it generally looks okay. Two examples from my DS1B20 test code ...

ReadSerialNumberOwIn:
OwOut C.0, %1001, ( READ_ROM )
OwIn C.0, %0000, ( b6, b7, b8, b9, b10, b11, b12, b13 )
Return

ReadTemperatureOwIn:
OwOut C.0, %1001, ( SKIP_ROM, TAKE_TEMP )
Pause 750
OwOut C.0, %1001, ( SKIP_ROM, READ_RESULT )
OwIn C.0, %0000, ( b0, b1 )
SerTxd( #w0, " ")

You could run the 'ReadSerialNumberOwIn:' code to see if it matches with what the 'ReadOwSn' command returns. I'd also recommend reading a whole set of data bytes first, getting fancy and adding DEBUG and other things which take time once you have that working. Maybe just read a single byte. Q : How do you know if it's returnng the right data, or if it isn't ?

But what's pin "7" on a 20X2 ? It's really advisable to use the proper port.pin identifier. It could simply be a case of using / connecting to wrong pin.
 

jmumby

Senior Member
I have tried.....

Code:
PAUSE 10
OWOUT C.0,%1001,(0x33)
OWIN  C.0,%0000,(b0,b1,b2,b3,b4,b5,b6,b7) 
DEBUG
Debug gets nothing using this so I must have something else fundamental wrong (hardware etc). I will have to read over the datasheet a bit slower.
 

hippy

Technical Support
Staff member
The hardware cannot get much simpler than 'one-wire' plus 0V and +V though I cannot remember if it needs a pull-up. If you have a DS18B20 you can use that; get the READOWSN command working then the OWOUT/OWIN.
 

BeanieBots

Moderator
One wire DOES need a pull-up.
It's bi-directional, to avoid "accidents" both ends are open collector, hence a pull-up is required.
 
Top