I asked about the slave device as some need a 8 bit and others  16 bit data word. I posted below all nicely formatted however the server rejected it so it's slightly less now formatted below.

I managed to get the new win10 desktop power apps also using the I2C tools cmds and it works well

i2cset -y 0 0x68 0x0D 0x0 w (reg 13d,15)
i2cset -y 0 0x68 0x14 0x0 w (reg 20d,4)
Bear in mind the following:
We are interacting with a device with 16 bit data words so
adjust accordingly for 8 bit data words
In our case we created a function method to read and a method
to write the devices and this is not shown supporting small/big endian
and also 8/16 bit data words so it can get very complex
We struggled so spent some time to master I2Cget and I2Cset
(I2Ctools) on the linux terminal to cross check the device
interaction..do this first and master it to save your sanity ie.
1) i2cset -y 0 0x68 0x15 0x8000 w //will set the data reg 21d as
0x8000
2) i2cget -y 0 0x68 0x15 w //this will get the data in 16 bit
format just written above...omit the 'w' for 8 bit words. The '0' is our
specific I2C port...maybe yours is 1 or 2 or 3
This cycles fast enough for us now at 10ms tasks to do repeated
reads or writes however in future we will streamline this with a I2C
bus analyzer to have repeats much faster. Read generally can be fast
although some device have a buffer write time of several ms so
consult the datasheet of the device you are using.
As the I2C protocol is open drain the I2Ctools and Codesys
debug can be used concurrently at the same time to cross check each
other.

//ReadFromDevice method-Read from I2C device one 16bit
word at a time

VAR
datatoget: ARRAY [0..2] OF WORD := [2(0)];
VAR_END
I2C_master.write(16#68, 16#15, 1);
I2C_master.read(16#68, ADR(datatoget), 2); //2 the is for 2
nibbles
If you are writing into device 16 bit data words then here is
something as a guide from our code as the array needs to be in a 16
bit word
VAR
datatostore: ARRAY [0..3] OF WORD := [2(0)];
VAR_END
datatostore[0] := 16#15;
datatostore[1] :=
OSCAT_BASIC.BYTE_OF_DWORD (regdata_to_write, 0);
//Buffer low nibble of the 16 bit data word
datatostore[2] :=
OSCAT_BASIC.BYTE_OF_DWORD (regdata_to_write, 1);
//Buffer high nibble of the 16 bit data word
//WriteToDevice method-Write to I2C device one 16bit word at
a time
I2C_master.write(16#68, 16#15, 1);
I2C_master.write(16#68, ADR(datatostore), 3);

Get Outlook for Android


From: talk@forge.forge.codesys.com <talk@forge.forge.codesys.com> on behalf of krishemanth <forge@codesys.com>
Sent: Tuesday, March 23, 2021 8:06:55 PM
To: [forge:talk] <Runtime@talk.forge.forge.codesys.com>
Subject: [forge:talk] Re: How to read I2C without specified device from FB
 

powertrick thanks for your quick response
you mean i2cbus-number by the i2c part? or the slave device?

its a controler stm with slave address of 0x18 on i2c-1 bus
iam doing something like i2cset -y 2 0x18 0x02 0x00 0x00 0x72 0x80 0x00 0x00 0x00 0x00 0x72 0x72 0x72 0x72 0x42 i from my target board.
how can i do the same from the codesys

thanks in advance,
-kris


How to read I2C without specified device from FB


Sent from forge.codesys.com because you indicated interest in https://forge.codesys.com/forge/talk/Runtime/

To unsubscribe from further messages, please visit https://forge.codesys.com/auth/subscriptions/