I2C SLAVE OPEN addr, mask, option, send_int, rcv_int
Enables the I2C module in slave mode.
‘addr’ is the slave I2C address.
‘mask’ is the address mask (normally 0, bits set as 1 will always match).
This allows the slave to respond to multiple addresses.
‘option’ is a number between 0 and 3 (normally this is set to 0).
1 = allows MMBasic to respond to the general call address. When this occurs the value of MM.I2C will be set to 4.
2 = treat the address as a 10 bit address
3 = combine 1 and 2 (respond to the general call address and use 10 bit addresses).
‘send_int’ is the line number or label of a send interrupt routine to be invoked when the module has detected that the master is expecting data.
‘rcv_int is the line number or label of a receive interrupt routine to be invoked when the module has received data from the master.
I2C SLAVE WRITE sendlen, senddata [,sendata ….]
Send the data to the I2C master. This command should be used in the send interrupt (ie in the ‘send_int_line’ when the master has requested data). Alternatively a flag can be set in the send interrupt routine and the command invoked from the main program loop when the flag is set.
‘sendlen is the number of bytes to send.
‘senddata’ is the data to be sent. This can be specified in various ways, see the I2C WRITE commands for details.
I2C SLAVE READ rcvlen, rcvbuf, rcvd
Receive data from the I2C master device. This command should be used in the receive interrupt (ie in the ‘rcv_int_line’ when the master has sent some data). Alternatively a flag can be set in the receive interrupt routine and the command invoked from the main program loop when the flag is set.
‘rcvlen’ is the maximum 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).
‘rcvd’ will contain the actual number of bytes received by the command.
I2C SLAVE CLOSE Disables the slave I2C module and returns the external I/O pins 12 and 13 to
a “not configured” state. Then can then be configured using SETPIN.
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