CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Thu Apr 25, 2019 7:54 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Feb 05, 2019 9:10 pm 
Offline

Joined: Tue Jan 29, 2019 7:05 pm
Posts: 4
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


Top
   
PostPosted: Wed Feb 06, 2019 10:25 am 
Offline

Joined: Tue Jan 29, 2019 7:05 pm
Posts: 4
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


Top
   
PostPosted: Fri Feb 08, 2019 8:45 am 
Offline

Joined: Mon Dec 13, 2010 3:02 pm
Posts: 53
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: learnetk and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited