CircuitGizmos

Electronic Products for Creative Minds

  • Home
  • Gizmo Store/Products
  • Documentation/Datasheets
  • Projects/Libraries
  • GizmoBlog
  • Services/Contact
    • Design
    • Contact Gizmo!
  • Your Gizmo Cart
    • Your Account
You are here: Home / GizmoBlog / MMBasic Language / Input and Output / I2C SLAVE

I2C SLAVE

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

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

A Ton of Documentation

Open all | Close all

Projects made by Gizmo, Friends, and Members

open all | close all

Recent GizmoBlog Musings

  • Altair 8800 using a ColorMax!
  • Re-energizing the ColorMax, Pt. 3

Visit us!

  • Facebook

Electronic Products for Creative Minds

CircuitGizmos is your source for electronic products that help you create your embedded projects. Here at CircuitGizmos.com you will find a friendly store filled with creative products and all of the documentation that you need to use these gizmos.

We create devices that we believe make electronics fun, but we also know that our products are used for professional designs. For decades we have designed products for commercial, military, and medical industries. Our gizmos here are great for engineers and hobbyists alike.

Copyright © 2008+ CircuitGizmos, L.L.C. All rights reserved

Image already added

Recently Viewed Products

Copyright © 2025 · Generate Pro Theme on Genesis Framework · WordPress · Log in