I2C

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 CMM2

Syntax:
I2C OPEN speed, timeout
I2C WRITE addr, option, sendlen, senddata [,sendata ....]
I2C READ addr, option, rcvlen, rcvbuf
I2C CLOSE

Description:
The I2C commands will send and receive data over an I2C channel.
I2C (no suffix) refers to channel 1 while commands I2C2 and I2C3 refer to channels 2 and 3 using the same syntax.
The number of available I2C channels varies depending on the device.
Also see Appendix B of the manuals.

I2C OPEN speed, timeout 
Enables the I2C module in master mode. 
'speed' is the clock speed (in KHz) to use and must be one of 100, 400 or 1000.
'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 WRITE addr, option, sendlen, senddata [,sendata ....]
Send data to the I2C slave device. 
'addr' is the slave's I2C address.
'option' can be 0 for normal operation or 1 to keep control of the bus after the command (a stop condition will not be sent at the completion of the command)
'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 as individual bytes on the command line.
Example: I2C WRITE &H6F, 0, 3, &H23, &H43, &H25
The data can be in a one dimensional array specified with empty brackets (ie, no dimensions). 'sendlen' bytes of the array will be sent starting with the first element. 
Example: I2C WRITE &H6F, 0, 3, ARRAY()
The data can be a string variable (not a constant).
Example: I2C WRITE &H6F, 0, 3, STRING$

I2C READ addr, option, rcvlen, rcvbuf
Get data from the I2C slave device. 'addr' is the slave's I2C address.
'option' can be 0 for normal operation or 1 to keep control of the bus after the command (a stop condition will not be sent at the completion of the command)
'rcvlen' is the number of bytes to receive.
'rcvbuf' is the variable or array used to save the received data - this can be:
A string variable. Bytes will be stored as sequential characters in the string.
A one dimensional array of numbers specified with empty brackets.
Received bytes will be stored in sequential elements of the array starting with the first.
Example: I2C READ &H6F, 0, 3, ARRAY()
A normal numeric variable (in this case rcvlen must be 1).

I2C CLOSE 
Disables the master I2C module and returns the I/O pins to a "not configured" state. They can then be configured using SETPIN. 
This command will also send a stop if the bus is still held.

 

 

Last edited: 29 September, 2020