PyICe.twoWireInterface

SMBus Interface Hardware Drivers

Classes

i2c_buspirate(interface_raw_serial) dangerous prototypes bus pirate communication board
i2c_dc590(interface_stream) Generic DC590/Linduino Driver.
i2c_dc590_list_read(interface_stream) use with Steve M’s linduino sketch extension DC590ListRead implementing ganged register reads
i2c_dummy([delay]) dummy interface for testing without any hardware. No actual communication occurs.
i2c_kernel(bus_number) communication class using Linux kernel driver
i2c_pic(interface_raw_serial) communication class to simplify talking to dave’s external i2c interface firmware on George’s development board (pic18F4553 and similar)
i2c_scpi(visa_interface) communication class to simplify talking to atmega32u4 with Steve/Eric SCPI firmware
i2c_scpi_sp(visa_interface, portnum, sclpin, ...) communication class to simplify talking to atmega32u4 softport with Steve/Eric SCPI firmware
i2c_scpi_testhook(serial_port)
twoWireInterface this is the master i2c class, all other i2c adapters inherit from this

Exceptions

i2cAcknowledgeError([value]) Got expected responses from I2C master device, but slave devices not acknowledging address or subsequent data bytes.
i2cAddressAcknowledgeError([value]) Got expected responses from I2C master device, but slave device not acknowledging address.
i2cCommandCodeAcknowledgeError([value]) Got expected responses from I2C master device, but slave device not acknowledging command code.
i2cDataAcknowledgeError([value]) Got expected responses from I2C master device and slave address, but slave devices not acknowledging subsequent data bytes.
i2cDataHighAcknowledgeError([value]) Got expected responses from I2C master device and slave address, but slave devices not acknowledging high data byte.
i2cDataLowAcknowledgeError([value]) Got expected responses from I2C master device and slave address, but slave devices not acknowledging low data byte.
i2cDataPECAcknowledgeError([value]) Got expected responses from I2C master device and slave address, but slave devices not acknowledging PEC data byte.
i2cError([value]) I2C Error Superclass - Don’t raise this exception.
i2cIOError([value]) I2C Bus communication failure, not otherwise specified.
i2cMasterError([value]) Unexpected response from I2C interface device, possibly caused by dropped USB packets, serial error, unpowered master, or other ‘computer’ problems.
i2cPECError([value]) Got expected responses from I2C master and slave acknowledging all bytes, but failed to reconcile SMBus packet error check.
i2cReadAddressAcknowledgeError([value]) Got expected responses from I2C master device, but slave device not acknowledging read address.
i2cStartStopError([value]) Failed to assert Start of Stop signals - not supported by all hardware
i2cUnimplementedError([value]) Feature currently unimplemented.
i2cWriteAddressAcknowledgeError([value]) Got expected responses from I2C master device, but slave device not acknowledging write address.
exception PyICe.twoWireInterface.i2cAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cError

Got expected responses from I2C master device, but slave devices not acknowledging address or subsequent data bytes.

exception PyICe.twoWireInterface.i2cAddressAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cAcknowledgeError

Got expected responses from I2C master device, but slave device not acknowledging address.

exception PyICe.twoWireInterface.i2cCommandCodeAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cAcknowledgeError

Got expected responses from I2C master device, but slave device not acknowledging command code.

exception PyICe.twoWireInterface.i2cDataAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cAcknowledgeError

Got expected responses from I2C master device and slave address, but slave devices not acknowledging subsequent data bytes.

exception PyICe.twoWireInterface.i2cDataHighAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cDataAcknowledgeError

Got expected responses from I2C master device and slave address, but slave devices not acknowledging high data byte.

exception PyICe.twoWireInterface.i2cDataLowAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cDataAcknowledgeError

Got expected responses from I2C master device and slave address, but slave devices not acknowledging low data byte.

exception PyICe.twoWireInterface.i2cDataPECAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cDataAcknowledgeError

Got expected responses from I2C master device and slave address, but slave devices not acknowledging PEC data byte.

exception PyICe.twoWireInterface.i2cError(value=None)[source]

Bases: exceptions.Exception

I2C Error Superclass - Don’t raise this exception. Use more specific subclass.

exception PyICe.twoWireInterface.i2cIOError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cError

I2C Bus communication failure, not otherwise specified.

exception PyICe.twoWireInterface.i2cMasterError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cError

Unexpected response from I2C interface device, possibly caused by dropped USB packets, serial error, unpowered master, or other ‘computer’ problems. Excludes communication problems with a device on the two-wire bus.

exception PyICe.twoWireInterface.i2cPECError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cError

Got expected responses from I2C master and slave acknowledging all bytes, but failed to reconcile SMBus packet error check.

exception PyICe.twoWireInterface.i2cReadAddressAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cAddressAcknowledgeError

Got expected responses from I2C master device, but slave device not acknowledging read address.

exception PyICe.twoWireInterface.i2cStartStopError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cError

Failed to assert Start of Stop signals - not supported by all hardware

exception PyICe.twoWireInterface.i2cUnimplementedError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cError, exceptions.NotImplementedError

Feature currently unimplemented. Write it if you want it!

exception PyICe.twoWireInterface.i2cWriteAddressAcknowledgeError(value=None)[source]

Bases: PyICe.twoWireInterface.i2cAddressAcknowledgeError

Got expected responses from I2C master device, but slave device not acknowledging write address.

class PyICe.twoWireInterface.i2c_buspirate(interface_raw_serial)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

dangerous prototypes bus pirate communication board

alert_response()

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()[source]

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_ack()[source]

Read 8 bits from slave transmitter and assert SDA during 9th acknowledge clock. Returns 8 bit data

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)[source]

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns one byte of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_byte_list(addr7, cc_list)

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)

read_byte with additional PEC byte read from slave.

read_nack()[source]

Read 8 bits from slave transmitter and release SDA during 9th acknowledge clock to request end of transmission. Returns 8 bit data

read_word(addr7, commandCode)[source]

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns two bytes of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_word_list(addr7, cc_list)

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)

read_word with additional PEC byte read from slave.

receive_byte(addr7)[source]

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)[source]

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

start()[source]

I2C Start - Falling SDA with SCL high. Returns True or False to indicate successful arbitration

stop()[source]

I2C Start - Rising SDA with SCL high. Returns True or False to indicate successful arbitration

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write(data8)[source]

Transmit 8 bits plus 9th acknowledge clock. Returns True or False to indicate slave acknowledge

write_addr(addr7)

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)[source]

The first byte of a Write Byte access is the command code. The next byte is the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data byte. The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_byte_pec(addr7, commandCode, data8)

write_byte with additional PEC byte written to slave.

write_word(addr7, commandCode, data16)[source]

The first byte of a Write Word access is the command code. The next two bytes are the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data word (low byte first). The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_word_pec(addr7, commandCode, data16)

write_word with additional PEC byte written to slave.

class PyICe.twoWireInterface.i2c_dc590(interface_stream)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

Generic DC590/Linduino Driver. Note that DC590 will not communicate unless it detects pullups on auxillary i2c port. Linduino does not have above limitiation.

alert_response()

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

i2c_mode()[source]

Switch DC590 I2C/SPI mux to SPI

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte_list(addr7, cc_list)

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)[source]

SMBus Read Byte Protocol with Packet Error Checking. Slave device address specified in 7-bit format. Returns 8-bit data from slave.

read_word_list(addr7, cc_list)

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)[source]

SMBus Read Word Protocol with Packet Error Checking. Slave device address specified in 7-bit format. Returns 16-bit data from slave.

receive_byte(addr7)

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write_addr(addr7)

compute 8-bit write address from 7-bit address

class PyICe.twoWireInterface.i2c_dc590_list_read(interface_stream)[source]

Bases: PyICe.twoWireInterface.i2c_dc590

use with Steve M’s linduino sketch extension DC590ListRead implementing ganged register reads todo: add PEC support to .ino and Python.

alert_response()

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()

close the underlying (serial) interface

disable_streaming()[source]

Turn off streaming I2C data and flush buffers.

enable_streaming_word_list()[source]

Turn on streaming I2C data Uses the chip address and commandCode list set up with previous read_{word,byte}_list() command. Not really compatible with PyICe except in I2C-only stand alone data logger mode.

high_byte(data16)

Select upper byte from 16-bit data

i2c_mode()

Switch DC590 I2C/SPI mux to SPI

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte_list(addr7, cc_list, PEC=False)[source]

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 This method overloads twoWireInterface.read_byte_list() to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)[source]

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 This method overloads twoWireInterface.read_byte_list_pec() to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)

SMBus Read Byte Protocol with Packet Error Checking. Slave device address specified in 7-bit format. Returns 8-bit data from slave.

read_streaming_byte_list()[source]

Incomplete stream read handler.

read_streaming_byte_list_pec()[source]

Incomplete stream read handler.

read_streaming_word_list()[source]

Return dictionary of single read results. Expects streaming to have been previously enabled using enable_streaming_word_list() This method must be called often enough in the main loop to keep buffers from overflowing. The main loop should spend time here on blocking IO as data fills the serial buffer if the computer is fast enough to keep up. Not really compatible with PyICe except in I2C-only stand alone data logger mode because of this blocking IO speed requirement.

read_streaming_word_list_pec()[source]

Incomplete stream read handler.

read_word_list(addr7, cc_list, PEC=False)[source]

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 This method overloads twoWireInterface.read_word_list() to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)[source]

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 This method overloads twoWireInterface.read_word_list_pec() to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)

SMBus Read Word Protocol with Packet Error Checking. Slave device address specified in 7-bit format. Returns 16-bit data from slave.

receive_byte(addr7)

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write_addr(addr7)

compute 8-bit write address from 7-bit address

class PyICe.twoWireInterface.i2c_dummy(delay=0)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

dummy interface for testing without any hardware. No actual communication occurs.

alert_response()

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_ack()[source]

don’t do anything. Return random 8-bit value

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns one byte of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_byte_list(addr7, cc_list)

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)

read_byte with additional PEC byte read from slave.

read_nack()[source]

don’t do anything. Return random 8-bit value

read_word(addr7, commandCode)

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns two bytes of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_word_list(addr7, cc_list)

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)

read_word with additional PEC byte read from slave.

receive_byte(addr7)

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

resync_communication()[source]

don’t do anything.

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

start()[source]

don’t do anything. Return value indicates that transaction was successful.

stop()[source]

don’t do anything. Return value indicates that transaction was successful.

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write(data8)[source]

don’t do anything. Return value indicates that transaction was successful.

write_addr(addr7)

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)

The first byte of a Write Byte access is the command code. The next byte is the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data byte. The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_byte_pec(addr7, commandCode, data8)

write_byte with additional PEC byte written to slave.

write_word(addr7, commandCode, data16)

The first byte of a Write Word access is the command code. The next two bytes are the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data word (low byte first). The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_word_pec(addr7, commandCode, data16)

write_word with additional PEC byte written to slave.

class PyICe.twoWireInterface.i2c_kernel(bus_number)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

communication class using Linux kernel driver requires py-smbus library provided as part of lm-sensors project i2c-tools library you may need to go to PyICe/deps/i2c-tools and build i2c-tools and py-smbus on your machine before this will work (Make/gcc) alternatively, install python-smbus and i2c-tools from your distribution’s package manager (apt-get,yum,opkg,port,etc). note that the library names for the various protocols do not match the SMBus protocol specification.

alert_response()[source]

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA

alert_response_pec()[source]

Alert Response Query to SMBALERT# interrupt with Packet Error Check

Returns 7 bit address of responding device. Returns None if no response to ARA

block_process_call(addr7, commandCode, dataByteListWrite)[source]

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)[source]

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)[source]

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)[source]

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)[source]

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)[source]

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)[source]

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)[source]

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)[source]

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_ack()

Read 8 bits from slave transmitter and assert SDA during 9th acknowledge clock. Returns 8 bit data

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)[source]

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns one byte of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_byte_list(addr7, cc_list)

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)[source]

read_byte with additional PEC byte read from slave.

read_nack()

Read 8 bits from slave transmitter and release SDA during 9th acknowledge clock to request end of transmission. Returns 8 bit data

read_word(addr7, commandCode)[source]

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns two bytes of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_word_list(addr7, cc_list)

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)[source]

read_word with additional PEC byte read from slave.

receive_byte(addr7)[source]

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)[source]

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

resync_communication()

attempt to correct problems caused by dropped/duplicate characters in serial buffer, etc. Don’t do anything here. Method must be overloaded to implement hardware-specific recovery procedure.

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)[source]

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)[source]

send_byte with additional PEC byte written to slave.

start()

I2C Start - Falling SDA with SCL high. Returns True or False to indicate successful arbitration

stop()

I2C Stop - Rising SDA with SCL high. Returns True or False to indicate successful arbitration

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write(data8)

Transmit 8 bits plus 9th acknowledge clock. Returns True or False to indicate slave acknowledge

write_addr(addr7)

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)[source]

The first byte of a Write Byte access is the command code. The next byte is the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data byte. The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_byte_pec(addr7, commandCode, data8)[source]

write_byte with additional PEC byte written to slave.

write_word(addr7, commandCode, data16)[source]

The first byte of a Write Word access is the command code. The next two bytes are the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data word (low byte first). The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_word_pec(addr7, commandCode, data16)[source]

write_word with additional PEC byte written to slave.

class PyICe.twoWireInterface.i2c_pic(interface_raw_serial)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

communication class to simplify talking to dave’s external i2c interface firmware on George’s development board (pic18F4553 and similar) requires pySerial

alert_response()

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()[source]

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns one byte of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_byte_list(addr7, cc_list)

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)

read_byte with additional PEC byte read from slave.

read_word(addr7, commandCode)[source]

faster way to do an smbus read word

read_word_list(addr7, cc_list)

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)

read_word with additional PEC byte read from slave.

receive_byte(addr7)

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write_addr(addr7)

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)

The first byte of a Write Byte access is the command code. The next byte is the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data byte. The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_byte_pec(addr7, commandCode, data8)

write_byte with additional PEC byte written to slave.

write_word(addr7, commandCode, data16)

The first byte of a Write Word access is the command code. The next two bytes are the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data word (low byte first). The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_word_pec(addr7, commandCode, data16)

write_word with additional PEC byte written to slave.

class PyICe.twoWireInterface.i2c_scpi(visa_interface)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

communication class to simplify talking to atmega32u4 with Steve/Eric SCPI firmware requires pySerial

alert_response()[source]

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA

alert_response_pec()[source]

Alert Response Query to SMBALERT# interrupt with Packet Error Check Returns 7 bit address of responding device. Returns None if no response to ARA

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()[source]

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)[source]

faster way to do an smbus read byte

read_byte_pec(addr7, commandCode)[source]

faster way to do an smbus read byte

read_word(addr7, commandCode)[source]

faster way to do an smbus read word

read_word_pec(addr7, commandCode)[source]

faster way to do an smbus read word

receive_byte(addr7)

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write_addr(addr7)

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)[source]

faster way to do an smbus write byte

write_byte_pec(addr7, commandCode, data8)[source]

faster way to do an smbus write byte

write_word(addr7, commandCode, data16)[source]

faster way to do an smbus write word

write_word_pec(addr7, commandCode, data16)[source]

faster way to do an smbus write word

class PyICe.twoWireInterface.i2c_scpi_sp(visa_interface, portnum, sclpin, sdapin, pullup_en)[source]

Bases: PyICe.twoWireInterface.twoWireInterface

communication class to simplify talking to atmega32u4 softport with Steve/Eric SCPI firmware requires pySerial

alert_response()

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)

block_write with additional PEC byte written to slave.

check_size(data, bits)

make sure data fits within word of length “bits”

close()[source]

close the underlying (serial) interface

high_byte(data16)

Select upper byte from 16-bit data

low_byte(data16)

Select lower byte from 16-bit data

pec(byteList)

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_addr(addr7)

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)[source]

faster way to do an smbus read byte

read_byte_list(addr7, cc_list)

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)

read_byte with additional PEC byte read from slave.

read_word(addr7, commandCode)[source]

faster way to do an smbus read word

read_word_list(addr7, cc_list)

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)

read_word with additional PEC byte read from slave.

receive_byte(addr7)

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)

receive_byte with additional PEC byte read from slave.

restart()

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

scan()

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)

send_byte with additional PEC byte written to slave.

word(lowByte, highByte)

Return 16-bit value from two SMBus bytes

write_addr(addr7)

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)[source]

faster way to do an smbus write byte

write_byte_pec(addr7, commandCode, data8)

write_byte with additional PEC byte written to slave.

write_word(addr7, commandCode, data16)[source]

faster way to do an smbus write word

write_word_pec(addr7, commandCode, data16)

write_word with additional PEC byte written to slave.

class PyICe.twoWireInterface.twoWireInterface[source]

Bases: object

this is the master i2c class, all other i2c adapters inherit from this

All SMBus Protocols are implemented generically with I2C Primitives Board specific subclasses should overload as necessary for increased performance addr7 is the 7-bit chip address The 8-bit read/write addresses are computed locally

alert_response()[source]

Another optional signal is an interrupt line for devices that want to trade their ability to master for a pin. SMBALERT# is a wired-AND signal just as the SMBCLK and SMBDAT signals are. SMBALERT# is used in conjunction with the SMBus General Call Address. Messages invoked with the SMBus are 2 bytes long. A slave-only device can signal the host through SMBALERT# that it wants to talk. The host processes the interrupt and simultaneously accesses all SMBALERT# devices through the Alert Response Address (ARA). Only the device(s) which pulled SMBALERT# low will acknowledge the Alert Response Address. The host performs a modified Receive Byte operation. The 7 bit device address provided by the slave transmit device is placed in the 7 most significant bits of the byte. The eighth bit can be a zero or one.

Returns 7 bit address of responding device. Returns None if no response to ARA.

alert_response_pec()[source]

Alert Response Query to SMBALERT# interrupt with Packet Error Check. Returns 7 bit address of responding device. Returns None if no response to ARA.

block_process_call(addr7, commandCode, dataByteListWrite)[source]

The block write-block read process call is a two-part message. The call begins with a slave address and a write condition. After the command code the host issues a write byte count (M) that describes how many more bytes will be written in the first part of the message. If a master has 6 bytes to send, the byte count field will have the value 6 (0000 0110b), followed by the 6 bytes of data. The write byte count (M) cannot be zero. The second part of the message is a block of read data beginning with a repeated start condition followed by the slave address and a Read bit. The next byte is the read byte count (N), which may differ from the write byte count (M). The read byte count (N) cannot be zero. The combined data payload must not exceed 32 bytes. The byte length restrictions of this process call are summarized as follows: • M ≥ 1 byte • N ≥ 1 byte • M + N ≤ 32 bytes The read byte count does not include the PEC byte. The PEC is computed on the total message beginning with the first slave address and using the normal PEC computational rules. It is highly recommended that a PEC byte be used with the Block Write-Block Read Process Call. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

block_process_call_pec(addr7, commandCode, dataByteListWrite)[source]

block write-block read process call with additional PEC byte read from slave.

block_read(addr7, commandCode)[source]

A Block Read differs from a block write in that the repeated START condition exists to satisfy the requirement for a change in the transfer direction. A NACK immediately preceding the STOP condition signifies the end of the read transfer.

block_read_pec(addr7, commandCode)[source]

block_read with additional PEC byte read from slave.

block_write(addr7, commandCode, dataByteList)[source]

The Block Write begins with a slave address and a write condition. After the command code the host issues a byte count which describes how many more bytes will follow in the message. If a slave has 20 bytes to send, the byte count field will have the value 20 (14h), followed by the 20 bytes of data. The byte count does not include the PEC byte. The byte count may not be 0. A Block Read or Write is allowed to transfer a maximum of 32 data bytes.

block_write_pec(addr7, commandCode, dataByteList)[source]

block_write with additional PEC byte written to slave.

check_size(data, bits)[source]

make sure data fits within word of length “bits”

close()[source]

close the underlying (serial) interface

high_byte(data16)[source]

Select upper byte from 16-bit data

low_byte(data16)[source]

Select lower byte from 16-bit data

pec(byteList)[source]

http://smbus.org/specs/smbus20.pdf Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of the bits as received. Calculating the PEC for transmission or reception is implemented in a method chosen by the device manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some example CRC-8 methods. The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation includes all bytes in the transmission, including address, command and data. The PEC calculation does not include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed over the entire message from the first START condition. Whether a device implements packet error checking may be determined by the specification revision code that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart Battery Selector. See these individual specifications for exact revision coding identities. It may also be discovered in the UDID, defined in section 5.6.1, for other devices.

process_call(addr7, commandCode, data16)[source]

The process call is so named because a command sends data and waits for the slave to return a value dependent on that data. The protocol is simply a Write Word followed by a Read Word without the Read- Word command field and the Write-Word STOP bit. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

process_call_pec(addr7, commandCode, data16)[source]

process_call with additional PEC byte read from slave.

quick_command_rd(addr7)[source]

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

quick_command_wr(addr7)[source]

Here, part of the slave address denotes the command – the R/W# bit. The R/W# bit may be used to simply turn a device function on or off, or enable/disable a low-power standby mode. There is no data sent or received. The quick command implementation is good for very small devices that have limited support for the SMBus specification. It also limits data on the bus for simple devices.

read_ack()[source]

Read 8 bits from slave transmitter and assert SDA during 9th acknowledge clock. Returns 8 bit data

read_addr(addr7)[source]

compute 8-bit read address from 7-bit address

read_byte(addr7, commandCode)[source]

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns one byte of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_byte_list(addr7, cc_list)[source]

Return dictionary of read_byte results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_list_pec(addr7, cc_list)[source]

Return dictionary of read_byte_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_byte_pec(addr7, commandCode)[source]

read_byte with additional PEC byte read from slave.

read_nack()[source]

Read 8 bits from slave transmitter and release SDA during 9th acknowledge clock to request end of transmission. Returns 8 bit data

read_word(addr7, commandCode)[source]

Reading data is slightly more complicated than writing data. First the host must write a command to the slave device. Then it must follow that command with a repeated START condition to denote a read from that device’s address. The slave then returns two bytes of data. Note that there is no STOP condition before the repeated START condition, and that a NACK signifies the end of the read transfer.

read_word_list(addr7, cc_list)[source]

Return dictionary of read_word results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_list_pec(addr7, cc_list)[source]

Return dictionary of read_word_pec results. Reads each commandCode of cc_list in turn at chip address addr7 Overload this method to improve communication speed when the instrument supports it.

read_word_pec(addr7, commandCode)[source]

read_word with additional PEC byte read from slave.

receive_byte(addr7)[source]

The Receive Byte is similar to a Send Byte, the only difference being the direction of data transfer. A simple device may have information that the host needs. It can do so with the Receive Byte protocol. The same device may accept both Send Byte and Receive Byte protocols. A NACK (a ‘1’ in the ACK bit position) signifies the end of a read transfer.

receive_byte_pec(addr7)[source]

receive_byte with additional PEC byte read from slave.

restart()[source]

I2C Re-Start - Falling SDA with SCL high between start and stop condition. Implement only if restart requires a different action than a normal start in underlying hardware. Returns True or False to indicate successful arbitration

resync_communication()[source]

attempt to correct problems caused by dropped/duplicate characters in serial buffer, etc. Don’t do anything here. Method must be overloaded to implement hardware-specific recovery procedure.

scan()[source]

Find all devices on bus by checking acknowledge of each address in turn.

send_byte(addr7, data8)[source]

A simple device may recognize its own slave address and accept up to 256 possible encoded commands in the form of a byte that follows the slave address. All or parts of the Send Byte may contribute to the command. For example, the highest 7 bits of the command code might specify an access to a feature, while the least significant bit would tell the device to turn the feature on or off. Or, a device may set the “volume” of its output based on the value it received from the Send Byte protocol.

send_byte_pec(addr7, data8)[source]

send_byte with additional PEC byte written to slave.

start()[source]

I2C Start - Falling SDA with SCL high. Returns True or False to indicate successful arbitration

stop()[source]

I2C Stop - Rising SDA with SCL high. Returns True or False to indicate successful arbitration

word(lowByte, highByte)[source]

Return 16-bit value from two SMBus bytes

write(data8)[source]

Transmit 8 bits plus 9th acknowledge clock. Returns True or False to indicate slave acknowledge

write_addr(addr7)[source]

compute 8-bit write address from 7-bit address

write_byte(addr7, commandCode, data8)[source]

The first byte of a Write Byte access is the command code. The next byte is the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data byte. The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_byte_pec(addr7, commandCode, data8)[source]

write_byte with additional PEC byte written to slave.

write_word(addr7, commandCode, data16)[source]

The first byte of a Write Word access is the command code. The next two bytes are the data to be written. In this example the master asserts the slave device address followed by the write bit. The device acknowledges and the master delivers the command code. The slave again acknowledges before the master sends the data word (low byte first). The slave acknowledges each byte, and the entire transaction is finished with a STOP condition.

write_word_pec(addr7, commandCode, data16)[source]

write_word with additional PEC byte written to slave.