This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LMX2594EVM: SPI control for automation to write register map

Part Number: LMX2594EVM
Other Parts Discussed in Thread: USB2ANY

Dear Team,

I try to set register values by using own source code (e.g., C, C++, Python) instead of using TICS Pro GUI.

After checking this page, there is a way to write register values using python.

Here, I attached the excerpt of python code in above link and there are several questions.

# Write and Read
numerator = 0xDEADBEEF
packet1 = 0x260000 + ((numerator >> 16) & 0xFFFF)
packet2 = 0x270000 + (numerator & 0xFFFF)
buf = ctypes.c_buffer(3) #register length is three bytes for LMX2594

buf[0] = (packet1 >> 16) & 0xFF
buf[1] = (packet1 >> 8) & 0xFF
buf[2] = packet1 & 0xFF
errCode = u2adll.u2aSPI_WriteAndRead(handle, 3, buf)
if errCode < 0: raise Exception('failed to write first packet')

buf[0] = (packet2 >> 16) & 0xFF
buf[1] = (packet2 >> 8) & 0xFF
buf[2] = packet2 & 0xFF
errCode = u2adll.u2aSPI_WriteAndRead(handle, 3, buf)
if errCode < 0: raise Exception('failed to write second packet')

buf[0] = 0xEF
buf[1] = 0x00
buf[2] = 0x00
errCode = u2adll.u2aSPI_WriteAndRead(handle, 3, buf)
if errCode < 0: raise Exception('failed to read R111')
rb_VCO_CAPCTRL = ord(buf[2]) # R111[7:0]

1. Objective of using packet 1 and packet 2

I wonder why using packet 1 and packet 2 before setting up register R111[7:0].

I just think defining the buffer size is sufficient like buf = ctypes.c_buffers(3).

Is it mandatory to set packet 1 and packet 2 before writing the several register values?

If so, is there any criterion to set up packet values?

2. Register name based programming method

In the example code, it seems register value is written based on register field name.

is there other method to write the register value based on register name e.g, R0=0x00251C similar to TICS Pro GUI?

3. buf array in example code

I expected buff array whose size is 3 means 3 bytes value and buf[0] is the address of the register and buf[1] & buf[2] are specific values.

However, buf[0] was configured to 'EF' in the above code when writing the R111 value, 

'EF' is not the address value of R111 so I want to know the meaning of each buf array value.

4. Validation method

After writing the register values in python code, is there a way to verify the register values in TICS Pro GUI?

Regards,

 Sung 

  • Hi Sung,

    The people who familiar with this is on vacation, I will let him response once he is back to work.

  • Hi Sung,

    1. The use of packet1 and packet2 variables was to illustrate the distinction between the data and the address components, as well as to illustrate the order in which each byte is committed to the buffer. If you wanted, you could just create the buffer of the appropriate size and directly set each byte each time you read and wrote registers. The critical criteria are that the u2aSPI_WriteAndRead functions always start from zero-index of the buffer, and will write/readback the programmed number of bytes. In either read or write case, the address byte(s) always need to be set, including potentially setting the highest bit to 1 on readback.
    2. We have an ActiveX API for TICS Pro which allows for higher level programming (see https://e2e.ti.com/support/clock-timing-group/clock-and-timing/f/clock-timing-forum/703263/lmx2595evm-tics-pro-control-with-matlab), but we haven't offered much documentation for it since it is mostly for internal use. In C:\Program Files (x86)\Texas Instruments\TICS Pro, there is an ActiveXTICSPro.dll file which can be used with win32com package:
      1. Install win32com package:
            pip install pywin32
      2. Generate the wrapper class (may need to run as admin shell):
            python -m win32com.client.makepy -o <optional path string>\TICSPro_API.py "c:\Program Files (x86)\Texas Instruments\TICS Pro\ActiveXTICSPro.tlb"
      3. In your script file, use the API:
        import TICSPro_API
        import win32com
        
        ticsapp = win32com.client.Dispatch("TICSPro.ActiveX")
        
        # Initialize is an API function to set the startup directory - most other
        # user facing API functions are documented in the excel spreadsheet in the
        # previously linked E2E post
        
        if hasattr(ticsapp,"Initialize"):
            ticsapp.Initialize(r"C:\Program Files (x86)\Texas Instruments\TICS Pro")

        I admit I haven't tried this specific code. But I adapted this code from our validation library, which we use daily. So it should be correct, or else only requires minor tweaks.
    3. hex(111) = 0x6F. Per the datasheet text following Figure 2 (SPI readback diagram), readback requires that the R/W bit be set to 1, and the readback bit is the MSB (0x80 for that byte). 0x80 | 0x6F = 0xEF, so the command will readback R111. The other two buffer byte values could be uninitialized without issues. I just wanted to illustrate that when you readback, buf[1] and buf[2] are different from the initially cleared values, indicating readback has occurred.
    4. To validate within TICS Pro with this code, you would have to close the USB2ANY handle, then manually configure TICS Pro to use the USB2ANY you just closed and read back the registers to verify the write process. Again, this is somewhat simplified in the ActiveX API for TICS Pro. The ActiveX API does not have a way to configure USB2ANY at this time. Keep in mind that this sample code is provided for programming SPI without using TICS Pro...

    At some point in the next year we plan to release a version of TICS Pro which exposes all the ActiveX capabilities more directly through a socket server API instead. Ideally this release will include an API manual and a python client

    Regards,

    Derek Payne

  • I appreciate your helpful response.  I'll try as you described. Again, thanks for the detailed reply.