# How to connect ds18b20 to microcontroller without two wire interface

#### Tinsae

Joined Jan 8, 2015
74
Dear all,
I have one master mcu (atmega32 ) and a pc , other slave mcu and input and output devices. I am able to connect pc rs232 with the master mcu. And I will connect the slaves to the master at SDA and SCL pin. But the proble comes when I need to connect ds18b20 to any mcu. As long as I know this sensor is always tied to SDA of mcu but that is already occupied by the slaves. So is there any way to connect ds18b20 temperature sensor to any pin of atmega32?

#### JohnInTX

Joined Jun 26, 2012
4,280
So is there any way to connect ds18b20 temperature sensor to any pin of atmega32?
You should be able to just hook it to an unused IO pin and bit bang it. But since it looks like you are going to have an I2C bus anyway, maybe just use a temperature sensor with an I2C interface and treat it as another slave. Alternately, use an analog sensor and one of the ADC inputs.

#### jpanhalt

Joined Jan 18, 2008
10,214
Have your heard of the RS232 interface? It is often called one wire. Here is some code in MPASM:
Code:
Put232
;*******************************************************************************
;PUT232 (19200 baud) using hardware generator
;Transmission is initiated by writing a character to TXREG (Bank3). PIR1,TXIF is set
;when NO character is being held for transmission.  It is not valid immediately
;after a write to TXREG and becomes valid in the second instruction cycle
;NB: This sequence allows successive calls to PUT232.  TXIF is always valid, as
;at least one Tcy is required for a return/call sequence.
;*******************************************************************************
movlb     0              ;only necessary if all calls are not from Bank0
btfss     PIR1,TXIF      ;two bytes can be loaded at a time, if needed     |B0
bra       \$-1            ;                                                 |B0
movlb     3              ;                                                 |B3
movwf     TXREG          ;byte to be transmitted is in WREG                |B3
movlb     0              ;                                                 |B0
retlw     0

#### JohnInTX

Joined Jun 26, 2012
4,280
Have your heard of the RS232 interface? It is often called one wire.
It can be but I'm not sure it works for the DS18B20. That one uses a bi-directional interface on one wire with its own protocol - the master issues timed pulses and either holds a o or Hiz to write or pulses a different time and samples the 0 or Hiz from the slave to read. It's what was used for the old Dallas Semiconductor touch buttons and lots of new stuff too.

#### Attachments

• 378.5 KB Views: 1

#### jpanhalt

Joined Jan 18, 2008
10,214
It can be but I'm not sure it works for the DS18B20. That one uses a bi-directional interface on one wire with its own protocol - the master issues timed pulses and either holds a o or Hiz to write or pulses a different time and samples the 0 or Hiz from the slave to read. It's what was used for the old Dallas Semiconductor touch buttons and lots of new stuff too.
My error. I didn't read the question thoroughly and should have searched on the device, which would have lead to the Adafruit version before replying. Of course it could be bit banged as you note, but I would more simply get a different device. Adafruit suggests its TMP36 with analog output.

#### atferrari

Joined Jan 6, 2004
4,088
Dear all,
I have one master mcu (atmega32 ) and a pc , other slave mcu and input and output devices. I am able to connect pc rs232 with the master mcu. And I will connect the slaves to the master at SDA and SCL pin. But the proble comes when I need to connect ds18b20 to any mcu. As long as I know this sensor is always tied to SDA of mcu but that is already occupied by the slaves. So is there any way to connect ds18b20 temperature sensor to any pin of atmega32?
You should consider the protocol called "1 wire".
Pity you use ATMega. I developed my own software for the PIC family and really enjoyed the journey.
/EDIT
If IIRC, also alluded somewhere as "micro LAN".
/EDIT

#### atferrari

Joined Jan 6, 2004
4,088