I2C
Functionality overview
I2C commands enable communication with I2C devices connected to Red Pitaya’s extension connector. Control I2C bus initialization, device addressing, read/write operations, and clock stretching for interfacing with sensors, EEPROMs, and other I2C peripherals.
Important notes
I2C device path may vary between board models.
Device addresses are specified in 7-bit format (not including R/W bit).
Clock stretching support depends on connected device capabilities.
Use force mode carefully as it can interfere with devices in use.
Code examples
Here are some examples of how to use I2C communication:
Parameters and command table
Parameter options:
<mode> = {OFF, ON}Default:OFF<value> = {XXX | #HXX | #QXXX | #BXXXXXXXX}Value in Decimal, Hexadecimal, Octal, or Binary format.<data> = {XXX, ... | #HXX, ... | #QXXX, ... | #BXXXXXXXX, ... }Array of data values separated by commas.XXX= Dec format#HXX= Hex format#QXXX= Oct format#BXXXXXXXX= Bin format
SCPI |
API, Jupyter |
DESCRIPTION |
ECOSYSTEM |
|---|---|---|---|
I2C:DEV<addr> <path>Example:
I2C:DEV80 "/dev/i2c-0" |
C++:
rp_I2C_InitDevice(const char *device, uint8_t addr)Python:
rp_I2C_InitDevice(<device>, <addr>) |
Initializes settings for I2C.
-
<path> - Path to the I2C device.-
<addr> - Device address on the I2C bus in dec format. |
1.04-18 and up |
I2C:DEV? > <addr>Example:
I2C:DEV? > 80 |
C++:
rp_I2C_getDevAddress(int *address)Python:
rp_I2C_getDevAddress() |
Returns the current address of the device. |
1.04-18 and up |
I2C:FMODE <mode>Example:
I2C:FMODE ON |
C++:
rp_I2C_setForceMode(bool force)Python:
rp_I2C_setForceMode(<force>) |
Enables forced bus operation even if the device is in use. |
1.04-18 and up |
I2C:FMODE? > <mode>Example:
I2C:FMODE? > ON |
C++:
rp_I2C_getForceMode(bool *value)Python:
rp_I2C_getForceMode() |
Gets the current forced mode setting. |
1.04-18 and up |
I2C:Smbus:Read<reg>? > <value>Example:
I2C:Smbus:Read2? > 0 |
C++:
rp_I2C_SMBUS_Read(uint8_t reg, uint8_t *value)Python:
rp_I2C_SMBUS_Read(<reg>) |
Reads 8 bit data from the specified register using
the SMBUS protocol.
<reg> - Register address in dec format. |
1.04-18 and up |
I2C:Smbus:Read<reg>:Word? > <value>Example:
I2C:Smbus:Read2:Word? > 0 |
C++:
rp_I2C_SMBUS_ReadWord(uint8_t reg, uint16_t *value)Python:
rp_I2C_SMBUS_ReadWord(<reg>) |
Reads 16 bit data from the specified register using
the SMBUS protocol.
<reg> - Register address in dec format. |
1.04-18 and up |
- (NA)
|
C++:
rp_I2C_SMBUS_ReadCommand(uint8_t *value)Python:
rp_I2C_SMBUS_ReadCommand() |
Read command from I2C using the SMBUS protocol.
|
1.04-18 and up |
I2C:Smbus:Read<reg>:Buffer<size>? ><data>Example:
I2C:Smbus:Read2:Buffer2? > {0,1} |
C++:
rp_I2C_SMBUS_ReadBuffer(uint8_t reg, uint8_t *buffer, int *len)Python:
rp_I2C_SMBUS_ReadBuffer(<reg>, <buffer>, <size>) |
Reads buffer data from the specified register using
the SMBUS protocol.
<reg> - Register address in dec format.<size> - Read data size. |
1.04-18 and up |
I2C:Smbus:Write<reg> <value>Example:
I2C:Smbus:Write2 10 |
C++:
rp_I2C_SMBUS_Write(uint8_t reg, uint8_t value)Python:
rp_I2C_SMBUS_Write(<reg>, <value>) |
Writes 8-bit data to the specified register using
the SMBUS protocol.
<reg> - Register address in dec format. |
1.04-18 and up |
I2C:Smbus:Write<reg>:Word <value>Example:
I2C:Smbus:Write2:Word 10 |
C++:
rp_I2C_SMBUS_WriteWord(uint8_t reg, uint16_t value)Python:
rp_I2C_SMBUS_WriteWord(<reg>, <value>) |
Writes 16-bit data to the specified register using
the SMBUS protocol.
<reg> - Register address in dec format. |
1.04-18 and up |
- (NA)
|
C++:
rp_I2C_SMBUS_WriteCommand(uint8_t value)Python:
rp_I2C_SMBUS_WriteCommand(<value>) |
Write command to I2C using the SMBUS protocol.
|
1.04-18 and up |
I2C:Smbus:Write<reg>:Buffer<size> <data>Example:
I2C:Smbus:Write2:Buffer2 0,1 |
C++:
rp_I2C_SMBUS_WriteBuffer(uint8_t reg, uint8_t *buffer, int len)Python:
rp_I2C_SMBUS_WriteBuffer(<reg>, <buffer>, <len>) |
Writes buffer data to the specified register using
the SMBUS protocol.
<reg> - Register address in dec format.<size> - Read data size. |
1.04-18 and up |
I2C:IOctl:Read:Buffer<size>? > <data>Example:
I2C:IOctl:Read:Buffer2? > {0,1} |
C++:
rp_I2C_IOCTL_ReadBuffer(uint8_t *buffer, int len)Python:
rp_I2C_IOCTL_ReadBuffer(<buffer>, <len>) |
Reads data from the I2C device through IOCTL.
<size> - Read data size. |
1.04-18 and up |
I2C:IOctl:Write:Buffer<size> <data>Example:
I2C:IOctl:Write:Buffer2 {0,1} |
C++:
rp_I2C_IOCTL_WriteBuffer(uint8_t *buffer, int len)Python:
rp_I2C_IOCTL_WriteBuffer(<buffer>, <len>) |
Writes data to the I2C device via IOCTL.
<size> - Read data size. |
1.04-18 and up |
- (NA)
|
C++: N/A
Python:
Buffer(<size>) |
Creates a buffer for sending and receiving data. |
2.04-35 and up |
Note
SMBUS is a standardized protocol for communicating with I2C devices. Information about this protocol can be found in this link: SMBUS specifcations. IOCTL writes and reads data directly from I2C.