I2C OPEN speed, timeout
Enables the I2C module in master mode.
‘speed’ is a value between 10 and 400 (for bus speeds 10 kHz to 400 kHz).
‘timeout’ is a value in milliseconds after which the master send and receive commands will be interrupted if they have not completed. The minimum value is 100. A value of zero will disable the timeout (though this is not recommended).
I2C READ addr, option, rcvlen, rcvbuf
Get data from the I2C slave device.
‘addr’ is the slave I2C address.
‘option’ is a number between 0 and 3 (normally this is set to 0)
1 = keep control of the bus after the command (a stop condition will not be sent at the completion of the command)
2 = treat the address as a 10 bit address
3 = combine 1 and 2 (hold the bus and use 10 bit addresses).
‘rcvlen’ is the number of bytes to receive.
‘rcvbuf’ is the variable to receive the data – this can be a string variable (eg, t$), or the first element of a one dimensional array of numbers (eg, data(0)) or a normal numeric variable (in this case rcvlen must be 1).
I2C WRITE addr, option, sendlen, senddata [,sendata ….]
Send data to the I2C slave device.
‘addr’ is the slave I2C address.
‘option’ is a number between 0 and 3 (normally this is set to 0)
1 = keep control of the bus after the command (a stop condition will not be sent at the completion of the command)
2 = treat the address as a 10 bit address
3 = combine 1 and 2 (hold the bus and use 10 bit addresses).
‘sendlen’ is the number of bytes to send.
‘senddata’ is the data to be sent – this can be specified in various ways (all values sent will be between 0 and 255):
The data can be supplied in the command as individual bytes. Example:
I2C WRITE &H6F, 1, 3, &H23, &H43, &H25
The data can be in a one dimensional array. The subscript does not have to be zero and will be honoured; also bounds checking is performed. Example:
I2C WRITE &H6F, 1, 3, ARRAY(0)
The data can be a string variable (not a constant). Example:
I2C WRITE &H6F, 1, 3, STRING$
I2C CLOSE
Disables the I2C module and returns the I/O pins to a “not configured” state. These can then be configured using SETPIN. This command will also send a stop if the bus is still held.
Following an I2C write or read command the automatic variable MM.I2C will be set to indicate the result of the operation as follows:
0 = The command completed without error.
1 = Received a NACK response
2 = Command timed out
See also:
I2CS
MM.I2C
SETPIN
Leave a Reply