Action
I2CSTART generates an I2C start condition.
I2CSTOP generates an I2C stop condition.
I2CRBYTE receives one byte from an I2C-device.
I2CWBYTE sends one byte to an I2C-device.
Syntax
I2CSTART
I2CSTOP
I2CRBYTE var, 8|9
I2CWBYTE val
Remarks
var |
A variable that receives the value from the I2C-device. |
8/9 |
Specify 8 or ACK if there are more bytes to read. (ACK) Specify 9 or NACK if it is the last byte to read. (NACK) |
val |
A variable or constant to write to the I2C-device. |
This command works only with additional hardware. See appendix D.
These functions are provided as an addition to the I2CSEND and I2CRECEIVE functions.
See also
Example
'----- Writing and reading a byte to an EEPROM 2404 -----------------
Dim A As Byte
Const Adresw = 174 'write of 2404
Const Adresr = 175 'read adres of 2404
I2cstart 'generate start
I2cwbyte Adresw 'send slaveadres
I2cwbyte 1 'send adres of EEPROM
I2cwbyte 3 'send a value
I2cstop 'generate stop
Waitms 10 'wait 10 mS because that is the time that the chip needs to write the data
'----------now read the value back into the var a -------------------
I2cstart 'generate start
I2cwbyte Adresw 'write slaveadres
I2cwbyte 1 'write adres of EEPROM to read
I2cstart 'generate repeated start
I2cwbyte Adresr 'write slaveadres of EEPROM
I2crbyte A , 9 'receive value into a. 9 means last byte to receive
I2cstop 'generate stop
Print A 'print received value
End