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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
byRead:=i2c_master.read(16#20, ADR(byIn), 1); //Using a PCF8574
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 https://forge.codesys.com/drv/io-drivers/
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, forge.codesys.com is a good place for that.
Gesendet von meinem LG-H870 mit Tapatalk