update on the 1-wire bus master DS2482-x00 please

rmeldo

Senior Member
Hi forum,

I have successfully put several DS18B20 on a 1-wire bus and read them with the readtemp12 witha 40X1.

Looking at the Maxim site I came across the 1-wire bus master DS2482-100 which would allow to have a lot of 1-wire devices on a bus and interface to the datalogger board AXE110p which has the 18X on board, freeying a lot of inputs.

I read the datasheet and, due to my limited knowledge of electronics, I could not decide whether an integration with the PICAXE is possible.

I found threads on this forum dating back to 2005-2006. In those forums people were discussing about the possibilities of implementing the DS2482 on the Picaxe platform, but I found no threads reporting a successful implementation.

If any of you has done it, could you let us know?


Thanks

Riccardo
 

inglewoodpete

Senior Member
1-wire bus master DS2482-x00 is an i2c interface

After having a quick look at the DS2482 datasheet. It is a 1-wire master device that uses 12c to communicate with its host.

Quite an useful looking chip: I will probably try one but I have had no experience with it yet.
 

westaust55

Moderator
1-wire bus

Hi forum,

I have successfully put several DS18B20 on a 1-wire bus and read them with the readtemp12 with a 40X1.
Riccardo,
have you put these several DS18B20 temp senors on a single 1-wire bus or did you have each on its own 40X1 input pin?

If using a single one-wire bus can you provide further information on how you have achieved this.

thanks
westaust55
 

rmeldo

Senior Member
I had a go, prompted by BeanieBots, and I found I had enough info from the Picaxe basic manual to succeed.

I first wired up each DS18B20 one at the time and used the "readowsn" with the Picaxe 40X1 and noted down the 1-wire address.

Then I did the bus connection by putting 2 DS18B20 in parallel on the same Picaxe input pin and then used the "owin" command to read from each sensor by quoting its serial number.

HERE IS THE CODE:


symbol SCK = Output7
symbol CS = Output6
symbol MISO_1 = Input7
symbol MISO_2 = Input6


Symbol temp_1 = w0 ' b0 b1
Symbol temp_2 = w1 ' b2 b3
Symbol intPart = w2 ' b4 b5
Symbol decPart = w3 ' b6 b7
Symbol N = b8
Symbol isOpen_1 = b9
Symbol isOpen_2 = b10
Symbol DS_1 = w6 ' b12 b13
Symbol DS_2 = w7 ' b14 b15


init:
serout 5,N2400,(254,1) 'clear LCD



main:
gosub measTemp
gosub displayTemp
goto main



'----------------------------------------------------------
measTemp:

' read from the TWO MAX6675
' Setup
high CS
low SCK
temp_1 = 0
temp_2 = 0

low CS ' start transmission sequence

for N = 1 to 16
high SCK
temp_1 = temp_1 * 2 + MISO_1
temp_2 = temp_2 * 2 + MISO_2
low SCK
next

high CS 'terminate the transmission

' discard the last two bits which are not needed
temp_1 = temp_1/4
temp_2 = temp_2/4


' read DS18B20 on board
owout 5 , %1001,($55,$28,$2B,$CE,$EA,$00,$00,$00,$A2,$44)
pause 750
owout 5 , %1001,($55,$28,$2B,$CE,$EA,$00,$00,$00,$A2,$BE)
owin 5 , %0000,(b12,b13)

' read DS18B20 on wire
owout 5 , %1001,($55,$28,$F4,$4B,$16,$01,$00,$00,$49,$44)
pause 750
owout 5 , %1001,($55,$28,$F4,$4B,$16,$01,$00,$00,$49,$BE)
owin 5 , %0000,(b14,b15)

DS_1 = DS_1/4
DS_2 = DS_2/4

return



'----------------------------------------------------------
displayTemp:

' check whether the thermocouple circuits are open
isOpen_1 = temp_1//2
isOpen_2 = temp_2//2

if isOpen_1 = 1 then
serout 5,N2400,(254,128,"Op ")
else
temp_1 = temp_1 /2
intPart = temp_1/4
decPart = temp_1//4 * 25
serout 5,N2400,(254,128,"1=",#intPart,".",#decPart," ")
endif

if isOpen_2 = 1 then
serout 5,N2400,(254,192,"Op ")
else
temp_2 = temp_2 /2
intPart = temp_2/4
decPart = temp_2//4 * 25
serout 5,N2400,(254,192,"2=",#address)',".",#decPart," ")
endif

intPart = DS_1/4
decPart = DS_1//4 * 25
serout 5,N2400,(254,137,"3=",#intPart,".",#decPart," ")

intPart = DS_2/4
decPart = DS_2//4 * 25
serout 5,N2400,(254,201,"4=",#intPart,".",#decPart," ")

pause 50

return





I used a single 4k7 resistor to pull the input pin high.

So now I am up and running with temperature reading.

However this forces me to use a 40X1 or 28X1 if I want to use a bus.

If I used a 18X I would have to connect a single DS18B20 to its own dedicated input pin.

The 1-wire master (1-W to i2c) is a fantastic solution..... that's why I am asking for feedback from people who have connected to the Picaxe.

On phanderson site he sells a 14 pins pic which does the 1-wire to serial conversion ($7.95), but the chip doesn't implement the bus, instead it allows to read up to 7 DS18B20 (a sort of multiplexer?). Not quite what I was looking for.

So my question still stands

Regards

Riccardo
 
Last edited:

westaust55

Moderator
1-wire bus

Thanks for the information Riccardo.

Will certainly look over your code when inserted/uploaded.

I have only used a single DS18B20 todate so cannot help myslef with the 1-wire bus master IC.
 

Jeremy Leach

Senior Member
I can't qualify as 'big gun', but no I've not used a DS2482 ;) It looks a good approach. All I've done with DS18B20s is either use a single one, or multiple via an HEF4051 analog mux.
 

hippy

Ex-Staff (retired)
Not me I'm afraid, I've never used the DS2482-100 or 1-Wire devices beyond the READTEMP/12 commands. It looks simple enough to use the device and get it wired up, but getting the protocol right, sending what's required as and when and understanding what comes back, is always the hardest part.

Not a lot I can suggest there apart from sitting down with the datasheet, the same for the DS18B20 and a good description of 1-wire (TM) comms and working your way through it. Also have a trawl with Google or your favourite search engine to see if anyone else has undertaken any projects with it.

The PICAXE hides complexities and intricacies behind READTEMP and other high-level and apparently simplistic command, moving beyond that means having to have a much deeper understanding of all the technologies involved.
 

rmeldo

Senior Member
thanks for the replies.

it looks like I am on my own for this one.

Last night I read the datasheets for the wire master and the DS18B20.

It is clear that I woul dhave to use the hi2cread and hi2cwrite commands and implement the communication in this way.

I understand that "readtemp12" is not the right command because (I think) it implements the 1-Wire protocol, which it is what I want to get away from.

Thanks for the application notes Westaust


I guess the next step is to get hold of some chips and have a go..... I might need an oscilloscope for real this time.

Riccardo
 

retepsnikrep

Senior Member
I have implemented multiple temp sensors in my BMS project. I connected each sensor in turn to my config software which gets the serial for each device.

The I added that data to my Master software, and it has two devices currently on one input, I used a single 4.7k pull up on the line.

Works OK but I haven't tested the negative temp part as it hasn't been cold enough here :eek:

Code:
SensorSerial:

`The readowsn command reads the serial number and then puts the family code
`in b6, the serial number in b7 to b12, and the checksum in b13

`Note that you should not use variables b6 to b13 for other purposes in your
`program during a readowsn command.


	serout Video,Baud9600,(27,67,"Sensor Serial No",10,13) 		;Video Display	
	
Main:
	readowsn TempSensor			;Read serial number on input2

	serout Video,Baud9600,(#b6," ",#b7," ",#b8," ",#b9,10,10,13) 	;Video Display

	serout Video,Baud9600,(#b10," ",#b11," ",#b12," ",#b13,10,10,13) 	;Video Display
You get the idea this reads the serial for each device.

This next bit is the bit that reads the temp of two devices on same bus.

Code:
CheckTemp:			;Check Battery Pack temperature routine (Multiple DS18B20 I2C Sensors) Once per minute

`The owout lines become TempSensor,%1001,($55,xx,xx,xx,xx,xx,xx,xx,xx,$44) where xx = decimal serial no's for the I2C chips

`Sensor 1 (Front Battery Block)

	owout TempSensor,%1001,($55,40,16,70,22,1,0,0,170,$44)	;Send ‘reset’ then ‘Match ROM’
	pause 1500						;Wait 750ms (8mhz) with strong pullup
	owout TempSensor,%0001,($55,40,16,70,22,1,0,0,170,$BE)	;Send ‘reset’ then ‘Match ROM’

	gosub calculatetemp                                     ;Gosub Calculate Temperature routine
			
	poke Temp1, CountE					;Store Front Battery Temperature in Temp1 Ram Byte
	poke Temp1S, CountA					;Store Temperature Sign byte (+ or -)

`Sensor 2 (Rear Battery Block)

	owout TempSensor,%1001,($55,40,14,45,234,0,0,0,75,$44)	;Send ‘reset’ then ‘Match ROM’
	pause 1500						;Wait 750ms (8mhz) with strong pullup	
	owout TempSensor,%0001,($55,40,14,45,234,0,0,0,75,$BE)	;Send ‘reset’ then ‘Match ROM’
	
	gosub calculatetemp                                     ;Gosub Calculate Temperature routine
	
	poke Temp2, CountE					;Store Rear Battery Temperature in Temp2 Ram Byte
	poke Temp2S, CountA					;Store Temperature Sign byte (+ or -)

	return							;Return to main program loop	

;**************************************************************************************************************

CalculateTemp:

	owin  TempSensor,%0000,(b16,b17) 	;Read temp sensor result into w8 (b16,b17) PackTemp12
	

	If PackTemp12 > 2047 Then		;If PackTemp12 > 2047 then temperature reading is Negative
    	PackTemp12 = PackTemp12 ^ $ffff + 1	;Take twos complement of reading
	CountA = 45				;Set CountA to 45 (-) if temperature is negative
	else	
	CountA = 43				;Set CountA to 43 (+) if temperature is positive
	endif

	`Convert 12bit DS18B20 value to a valid temperature reading 
	CountW =  PackTemp12 * 6		;TC = value * 0.0625
	PackTemp12 = PackTemp12 * 25 / 100
	PackTemp12 = CountW + PackTemp12
	CountE = PackTemp12 / 100

	return					;Return to CheckTemp
You can ignore all my application specific code, peeks, pokes etc.
 
Last edited:

Technical

Technical Support
Staff member
You might want to edit your 'skip rom' comments to 'match rom' to avoid confusion for others!
 

westaust55

Moderator
DS2482-100 1-wire bus master

it looks like I am on my own for this one.

Last night I read the datasheets for the wire master and the DS18B20.

It is clear that I woul dhave to use the hi2cread and hi2cwrite commands and implement the communication in this way.

Riccardo
Before you use the HI2CREAD and HI2CWRITE commands, don't forget to use the HI2CSETUP command to set the i2c bus to the DS2482-100.

Depending upon the hi/lo connections you make to the IC physical A0 and A1 address pins on the DS2482-100, you will have an i2c slave address like
%00110aa0

I am sure you will not be entirely on your own. certainly others here who will pitch in and help when the need arises.
 

hippy

Ex-Staff (retired)
It is clear that I woul dhave to use the hi2cread and hi2cwrite commands and implement the communication in this way.
As best I can tell, it should be possible to use the 'standard' I2CREAD / I2CWRITE commands.

Your best approach will be methodical, one step at a time, get I2C working correctly first and prove it is before getting more ambitious with the next steps. Check the DS18B20 works with READTEMP before trying to read it via the I2C bridge. Using what you've used before and have experience with is always a good course. If it will work with 'standard' I2C commands, I'd use those, move to HI2C later for speed etc.

I doubt you'll be entirely on your own, it's just that big or unfamiliar projects are harder for people to quickly and casually give good responses to. More specific questions can often get you answers which will get you over smaller hurdles.
 

rmeldo

Senior Member
Moving forward,

I looked at the i2c communication protocol as required by the DS2482. There are a series of timed signals involved in the communication on the SDA and SCL lines.

My question aims at understanding what the readi2c and writei2c do, i.e. how much of the "bit banging" is already implemented by the above commands.

Taking for example the first sequence described in th example at page 19 of the DS2482-100 datasheet:

http://datasheets.maxim-ic.com/en/ds/DS2482-100-DS2482S-100.pdf

the work done by the microcontroller must be:

transmit Start signal
transmit device address set to write(1byte)
listen for acknowledgement (1 bit)
transmit command (1 byte)
listen for acknowledgement (1 bit)
transmit --> restart <-- signal <--- can Picaxe send this?
transmit device address set to read(1byte)
listen for acknowledgement (1 bit)
read the info supplied by the DS2482
don't acknowledge
transmit stop signal


This sequence is very similar to the portocol for writing to the DS1307. For that the sequence is as follows:

transmit Start signal
transmit device address set to write(1byte)
listen for acknowledgement (1 bit)
transmit memory address (1 byte)
listen for acknowledgement (1 bit)
transmit data (1 byte)
listen for acknowledgement (1 bit)
transmit data (1 byte)
listen for acknowledgement (1 bit)
transmit stop signal


So the questions are:

1) what exactly is the sequence implemented by i2cslave, writei2c and readi2c? (that is in the two forms "readi2c (variable)" and "readi2c location, (variable)" and "writei2c (variable)" and "writei2c location, (variable)")

2) are the commands (readi2c and writei2c ) capable of sending the "restart" signal which the DS2482 needs?


I realise that it is a quite detailed question, which might require the input from technical, but I think this might be (I hope so anyway) the major obstacle of the implementation.

Thanks

Riccardo
 

westaust55

Moderator
i2c to 1-wire

the PICAXE readi2c and writei2c commands do all the hard work for you such as hand shaking, acknowledgement etc.

In basic summary all you need to get right are:
1. the slave address of the device you want to communciate with
2. the correct number for any registers you need to set up
3. sending the data to the i2c slave device or reading data from the i2c slave device. For this you often need to also provide the address of the register to/from which the data must be written/read.

before you use the i2c read and write comamnd you must first use the i2cslave command to set up the PICAXE i2c lines to communicate with the desired i2c slave device. see manual 2 page 70.

so the setup is:
Code:
i2csetup  %00110aa0,  i2cfast, i2cbyte        ; where aa must reflect the state of the two address pins A1 and a0 respectively.
to perform a DS2482-100 device reset you must send the value $F0. (See datasheet page 10)

Code:
writei2c ($F0)                                          ; $F0 = %1111 0000
 
Last edited:

rmeldo

Senior Member
Thanks for further edits Westaust.

I understand that.

The next command then would be "readi2c (b0)" ? (where b0 is the destination varable in the Picaxe).

would that equate to the sequence below?:

transmit --> restart <-- signal <--- can Picaxe send this?
transmit device address set to read(1byte)
listen for acknowledgement (1 bit)
read the info supplied by the DS2482
don't acknowledge
transmit stop signal

Note that the specsheet differentiates between a "start" and a "restart", although they look pretty similar to me.

Riccardo
 

westaust55

Moderator
Control of the DS4282-100 i2c to one-wire device

You are on the track but it will take a bit more effort (ie program steps)
There are three registers in the DS2482-100 than you will need to read from.
1. Configuration register – access code $C3,
2. Read Data Register – access code $E1, and
3. Status Register – access code $F0.
To read from the desired register you must firsts end a “Set Read Pointer” command ($E1)
So the command to set up the read pointer to the desired register is:
Code:
Writei2c ($E1, $aa)    ; where aa is one of the three access codes mentioned above.

To read data from the one-wire bus aa would be $E1
Hmmmm, I can see people getting confused over a Set read Pointer command and a Read Data Register pointer as both have a value of $E1

To then write a byte onto the one-wire bus.
Code:
Writei2c ($A5, $bb)    ; where bb is the byte to be written to the bus
Note seems can only write one byte at a time, so may need duplicate write a byte to one-wire bus commands.
Finally to read a byte back form the one-wire bus,
Code:
Readi2c ($96, b0)    ; where b0 is the PICAXE register in which you want to place the byte value received
That is the basics.
There is another command to perform a reset of the 1-wire bus devices (but not the DS2482-100).
Any program will have to initially set the configuration register if the default is not what is required
And between commands the program will need to read the status register to verify:
(a) If there are devices actually on the 1-wire bus, and
(b) when the 1-wire busy is no longer busy
 

rmeldo

Senior Member
Thanks Westaust,

I did some reading myself last night, put pen to paper and I think I am up and running now.

I understand the details of what you are telling me and that tells me that I might be on the right track.


The key point was to understand the following:

1) the DS18B20 needs a defined 1-wire communication sequence. (I used the one at the top of page 18 of the DS18B20 datasheet in my example)

2) I need to implement the 1-wire sequence by a sequence of i2c commands sent to the DS2482. (I wrote this down to match the sequence at point 1))

3) I do that by using a sequence of writei2c and readi2c commands to the Picaxe. (I matched this to the sequence at point 2)


I will get down to it.

I need to create a series of subroutines that mirror the DS2482 commands. That will in effect become the Picaxe "driver" for the wire master.

I have no parts yet so it will take a while.

Thanks again

Riccardo
 

rmeldo

Senior Member
Thanks We55.

I cannot pull up the link. phanderson's site seems down.

Howewver I have written the code and got the samples yesterday.... ready to play at the weekend.

Whatch this space....


Riccardo
 

rmeldo

Senior Member
Hi,

I got the 1-Wire master working last night.

The software only uses two bytes to do all the normal operations through the i2c bus, including reading the temperature on the DS18B20s.

The only thing I did not implement is the scanning of the 1-wire bus to read all the devices serial numbers when more than one device is on the bus, as it takes a lot of code(hence memory space). I thought that I could do something like the "readowsn" command instead.

This however uses 8 bytes for reading and storing the 1-wire serial number off the devices (DS18B20 in my case). This might or might not be a problem, since the reading of the serial number is done once and for all for each sensor. However since the natural use for this wire master is for smaller Picaxes, I was thinking of actually poke the bytes into memory, rather than use up 8 variables.


The question is where.


Which memory location, in the RAM or EEPROM would you guys recommend I use to stay clear of areas which are used for something else?


thanks

Riccardo
 

westaust55

Moderator
RAM is the best if you are going to be changing data all the time.

EEPROM is much more variable depending upon which PICAXE you have but lowest memory locations are best in smaller chips where program and EEPROM storage use the same area.

Have a look at my memory map in post 14 here:
http://www.picaxeforum.co.uk/showthread.php?t=9525&page=2

Look at the white region in the SFR part at the botom left.
$50 = 80 decimal thru to $7F = 128 decimal
 
Last edited:

craigcurtin

Senior Member
Riccardo, did you get the I2C to 1wire working

Just wanting an update to see if you got anywhere with this and if you could post any code if possible ?

regards

Craig
 
Top