CP2114 B02 I2C Command Array Generator

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> BrianL on ‎03-30-2017 07:05 PM

Attached to this article is a python 3 script to generate the I2C command arrays for a CP2114-B02 device.

 

This script interprets the following commands to construct the command byte-array.

 

  • write(slaveAddress, data) - writes an array of data to the i2c slave with the address slaveAddresswithout issuing an I2C stop command at the end of the transaction
  • write_stop(slaveAddress, data) - writes an array of data to the i2c slave with the address slaveAddress, issuing an I2C stop command at the end of the transaction
  • stop() - issues an I2C stop command
  • delay_ms(delay) - delays the next command by delay milliseconds
  • delay_us(delay) - delays the next command by delay microseconds
  • reenumerate() - immediately reenumerates the CP2112 device
  • setGPIO(state, gpioNum) - sets the gpio gpioNum to state, where 1 = high, 0 = low

 

In addition to these commands, the command list must begin with one of the following sequence identifiers:

 

  • RESET_SEQUENCE - identifies this sequence of commands to be issued after reset
  • SUSPEND_SEQUENCE - identifies this sequence of commands to be issued before entering suspend mode
  • ACTIVE_SEQUENCE - identifies this sequence of commands to be issued when exiting suspend mode into active mode

Note - only one sequence can be generated at a time with this script. If all three sequences are needed, they will need to be generated individually, then appended together into one large byte array.

 

Here is an example image of the script running:

 

b02.png

 

The left panel is the 'input' field, where commands are typed. The right panel is the 'output' field, where the byte array is generated. The byte array is refreshed any time return/enter are pressed in the input field.

 

The bottom panel is for any errors that may arise.

 

As an example, this is the input text required to generate a configuration for the CS42L55 codec:

 

RESET_SEQUENCE
setGPIO(0, 4)
delay_us(250)
delay_us(250)
delay_us(250)
delay_us(250)
setGPIO(1, 4)
delay_us(1)
write_stop(0x94, [0x00, 0x99])
write_stop(0x94, [0x2E, 0x30])
write_stop(0x94, [0xB2, 0x07, 0xFD, 0xF8, 0xDC, 0xF8, 0x6C])
write_stop(0x94, [0x3A, 0xF8])
write_stop(0x94, [0xBC, 0xD3, 0x23, 0x81, 0x46])
write_stop(0x94, [0x00, 0x00])
write_stop(0x94, [0x03, 0x0A])
write_stop(0x94, [0x84, 0x02, 0x09])
write_stop(0x94, [0x06, 0x20])
write_stop(0x94, [0x2A, 0x00])
write_stop(0x94, [0x9A, 0xC4, 0xC4, 0xC4, 0xC4])
write_stop(0x94, [0x02, 0x08])
delay_ms(75)
write_stop(0x94, [0x9A, 0x7A, 0x00, 0x00])

 

This generates the following binary array:

 

F9 6E 00 47 04 64 FA 64 FA 64 FA 64 FA 47 84 64 01 57 03 94 00 99 50 57 
03 94 2E 30 50 57 08 94 B2 07 FD F8 DC F8 6C 50 57 03 94 3A F8 50 57 06
94 BC D3 23 81 46 50 57 03 94 00 00 50 57 03 94 03 0A 50 57 04 94 84 02
09 50 57 03 94 06 20 50 57 03 94 2A 00 50 57 06 94 9A C4 C4 C4 C4 50 57
03 94 02 08 50 44 4B 57 05 94 9A 7A 00 00 50 00

 

Syntax errors will be displayed in the bottom panel:

 

b02_error.png