CODESYS - the IEC 61131-3 automation software

Reading DS18B20 via DS2482-800
Page 1 of 1

Author:  Schmittlich [ Tue Feb 05, 2019 9:10 pm ]
Post subject:  Reading DS18B20 via DS2482-800

Hello, I am mew with CODESYS
But I do have experience with TwinCAT 2

I want to read temperature from 8x DS2482 via I2C.
On one port of DS2482-800 only one DS18B20 - so they can be replaced without changing the ID of the DS18B20.
Therfore I want to create a simple Library for the DS2482-800

With a MICROCHIP-PIC I can already read the DS18B20.
Now I want to do the same with CODESYS on the Raspberry 3

Can anyone assist me, in this project?
As a first step, I would be happy to create some Functions to acces the DS2482.
But right now, I have proplems to use the low-level comands like write8 or read8 I2C-comands inside a regular Function block.

Lets start with the first step ... sending a reset to the DS2482

This is, how I dit it with my PIC16F887:
' Returns: TRUE if device was reset
' FALSE device not detected or failure to perform reset
Function ds2482_reset() As Bit
Dim xstatus As Byte
Dim acknowledge As Bit
ds2482_reset = False
'// device reset
I2CWrite1 sda, scl, i2c_addressw, cmd_drst
WaitUs 10
I2CRead1 sda, scl, i2c_addressr, xstatus
'// check For failure due To incorrect Read back of STATUS
xstatus = xstatus And 0xf7
If xstatus = 0x10 Then ds2482_reset = True
End Function

Author:  Schmittlich [ Wed Feb 06, 2019 10:25 am ]
Post subject:  Re: Reading DS18B20 via DS2482-800

OK, in meantime I found the first important trick how to use the "low-level" comands.
Add I2C-Master and then use following syntax inside the program:

byWrite:=i2c_master.write(16#20, ADR(byOut), 1); //Using a PCF8574, ADR(byIn), 1); //Using a PCF8574

Author:  Ingo Hornberger [ Fri Feb 08, 2019 8:45 am ]
Post subject:  Re: Reading DS18B20 via DS2482-800

Nice that you found it already. If you like to turn your library into a real I/O driver afterwards, please take a look at

Have fun, and if you have further questions regarding generic I/O stuff feel free to ask.

And if you like to share your work, is a good place for that. ;)

Gesendet von meinem LG-H870 mit Tapatalk

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited