I2CRECEIVE

Top  Previous  Next

Action

Receives data from an I2C serial slave device.

 

 

Syntax

I2CRECEIVE slave, var

I2CRECEIVE slave, var , b2W, b2R

 

 

Remarks

Slave

A byte, Word/Integer variable or constant with the slave address from the I2C-device.

Var

A byte or integer/word variable that will receive the information from the I2C-device.

b2W

The number of bytes to write.

 

Be cautious not to specify too many bytes!

b2R

The number of bytes to receive.

 

Be cautious not to specify too many bytes!

 

You must specify the base address of the slave chip because the read/write bit is set/reset by the software.

When an error occurs, the internal ERR variable will return 1. Otherwise it will be set to 0.

 

 

ASM

The I2C routines are located in the i2c.lib/i2c.lbx files.

 

 

See also

I2CSEND, I2CSTART , I2CSTOP, I2CRBYTE , I2CWBYTE

 

 

Example

Config Sda = Portb.5

Config Scl = Portb.7

Dim X As Byte , Slave As Byte

X = 0                                                       'reset variable

Slave = &H40                                               'slave address of a PCF 8574 I/O IC

I2creceive Slave , X                                       'get the value

Print X                                                     'print it

 

 

Dim Buf(10)as Byte

Buf(1) = 1 : Buf(2) = 2

I2creceive Slave , Buf(1) , 2 , 1                           'send two bytes and receive one byte

Print Buf(1)                                               'print the received byte

End