Breadcrumbs

I2C

The i2c connector in the node can be added in the device tree of the KCH Control ARM VFP Linux.

image2021-2-16_10-12-56.png

Parameters

Parameter

Description 

I2C Port

Linux Device File Path of i2c port (see HW chapter)

With the new i2c master node there are read/write commands available.

i2cMaster.read (METH)

METHOD read : DINT

This method is used to directly read nBufferLen bytes from a device with a certain address return value: number of bytes that have actually been read.

Parameters

Parameter

Description 

usiAddress [in]

address of i²c device  (7-Bit)

pbyBuffer [in] 

pointer to area, where the bytes are copied

nBufferLen [in]

number of bytes to read


Return Values

Return Values 

Description 

read

number of bytes that have actually been read

0: read failed

Example

C++
diRetvalRead: DINT;
diRetvalWrite: DINT;
usiAddress: USINT := 16#50;
dataAddress : BYTE := 16#15;
datatoread:  ARRAY [0..1] OF BYTE  := [2(0)];

dataAddress := 16#15;
diRetvalWrite := I2C_master.write(usiAddress, ADR(dataAddress), 1);  
diRetvalRead := I2C_master.read(usiAddress, ADR(datatoread), 2);

i2cMaster.write(METH)

METHOD write : DINT

This method is used to directly write nBufferLen bytes to a device with a certain address

Parameters

Parameter

Description 

usiAddress [in]

address of i²c device (7-Bit)

pbyBuffer [in] 

Pointer to the buffer that contains the data

nBufferLen [in]

number of bytes to write


Return Values

Return Values 

Description 

write

Number of bytes that have actually been written

0: write failed

Example

C++
diRetvalWrite: DINT;
usiAddress: USINT := 16#50;
dataAddress : BYTE := 16#15;
datatostore:  ARRAY [0..2] OF BYTE  := [3(0)];

datatostore[0] := dataAddress;
datatostore[1] := 1;
datatostore[2] := 1;
diRetvalWrite := I2C_master.write(usiAddress, ADR(datatostore), 3);


Hardware

SOM Evalboard:

HW Port

CODESYS I2C Port

I2C (X8)

'/dev/i2c-0'

imx6 WPC Board:

HW Port

CODESYS I2C Port

I2C (X4)

'/dev/i2c-0'


  • A read/write flag in the address parameter is not necessary.