I2CRECEIVE/de
Contents |
= (**COPIED FROM ENGLISH PAGE**) === Action
Receives data from an I2C serial slave device.
Syntax
I2CRECEIVE slave, var
I2CRECEIVE slave, var , b2W, b2R
Syntax Xmega
I2CRECEIVE slave, var , #const
I2CRECEIVE slave, var , b2W, b2R , #const
Remarks
Slave |
A byte, Word/Integer variable or constant with the slave address from the I2C-device.
I2C uses a 7 bit address from bit 1 to bit 7. Bit 0 is used to specify a read/write operation. In BASCOM the byte transmission address is used for I2C. This means that an I2C 7-bit address of 1 becomes &B10 = 2. And we say the address is 2. This is done so you can copy the address from the data sheets which are in the same format in most cases. So if you work with 7 bit address, you need to multiply the address by 2. |
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! |
#const |
For the Xmega, a channel constant that was specified with OPEN. |
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.
The I2CRECEIVE statement combines the i2cstart,i2cwbyte, i2crbyte and i2cstop statements.
For the xmega you can optional specify the channel. Without it, SPIC will be used.
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
Languages | English • Deutsch |
---|