A Convert to 8-bit String or Convert to 16-bit String Calc button can be used to convert an Integer value to either an 8-bit or 16-bit string, save it to a local variable, and then emit it from the StaticDigital I2C. The calc button is not available in the Cassini System library and must be copied from a Testplan to be used. Follow the steps below to import the Testplan and then copy the button and use in your Test panel.
To Use Convert to 8-bit String or Convert to 16-bit String Calc button:
- Download the .GZP attached below and Import with Guru Browser.
- Launch Cassini, use Test > Plans, (Type > demo, Device > demo) left click to highlight I2C_16-bit_LocalVar_example_StaticDigital and choose select button as shown in Figure 1.
- In the first panel, the Constant is converted using a Calc block with Smalltalk code inside and saved into a local variable. Choose 8-bit or 16-bit representation of the integer value with the corresponding calc block as seen in Figure 2.
- To use, copy the Test panel and paste into your Testplan or left click on the Convert to 8-bit String or Convert to 16-bit String calc button to paste the button into your Testplan. Connect the calc button input button to the Measurement or source decimal value and then connect the output to a System Save variable button.
- (Optional) To inspect the Smalltalk source code, choose Edit Block... from the right click menu by right clicking the yellow area of the calc block.
- The second panel then uses the local variable to emit the binary string (in this case a 16-bit value) on the I2CWrite as shown in Figure 3.
- Below is a capture of the emit of the integer value 61642 as 16-bit binary 1111 0000 1100 1010 as shown in Figure 4.
Note: Datalog worksheet will convert the binary back to decimal for display.
Download .GZP with sample program
Figure 1: Open Example Testplan
Figure 2: Convert to 8-bit or 16-bit Binary String
Figure 3: Example use of variable
Figure 4: Logic Analyze Capture