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

I2C

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 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 © 2023 · Generate Pro Theme on Genesis Framework · WordPress · Log in