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.

LMK04832EVM: Script to program LMK04832EVM device - C, Python, etc.

Part Number: LMK04832EVM
Other Parts Discussed in Thread: USB2ANY, LMK04832

To program the LMK04832EVM, TI recomends using the TICS Pro software and the USB2ANY. However, I would like to program it using a smaller device, like a raspberry pi. Does anyone have a Python or C script that is able to program the LMK using the raspberry pi? Also, if possible, please share how your pins are connected from the raspberry pi to the LMK device. I have the register values to be written to the LMK, but I don't have a working script that can communicate and send the values to the device. I have tried many ways but have not been successful yet, so it'll be great if someone can help me. Thanks a lot in advance!

  • Yu Jie,

    We don't have any official support for Raspberry Pi, so my suggestions here are the extent of assistance I can provide from quickly consulting documentation - I can answer questions about LMK04832(EVM) in greater detail but likely cannot provide much more assistance on RPi concepts or linux SPI kernel drivers. 

    I can suggest the spidev library as a simple python package to expose SPI on linux. I haven't tested the code below, so it may be the case that RPi does weird things with the chip select, but from what I can glean online it seems the writebytes function toggles chip select at the beginning and end of the list - so three bytes list argument to writebytes should do what we want. TICS Pro can export hex registers to a text file, which can be converted programmatically or manually to a sequence of three-byte lists. A tested example of how this could be done is included below.

    import spidev
    # based on hardware, exact bus and CS pin exposed will differ
    bus, cs = 0, 0
    myspi = spidev(bus, cs)
    # configure for LMK04832
    myspi.max_speed_hz = 2_000_000
    myspi.mode = 2 # CPOL=1, CPHA=0
    # example write data - sets POWERDOWN=1 (easy to observe change in supply current)
    # tested example to convert hex registers .txt file to list of three-byte lists
    with open("HexRegisterValues.txt",'r') as f:
        lines = f.readlines()
    bytes_to_write = []
    for line in lines:
        # format is 'R0 (INIT)\t0x000090\n'; split by \t, take hex after 0x
        hexval = int(line.split('\t')[1][2:], 16)
        # shift and mask individual bytes
        bytes_to_write.append([(hexval>>16)&0xff, (hexval>>8)&0xff, hexval&0xff])

    The pinout for SPI can be found in our EVM user's guide schematic. Pin 1 on the EVM header should have silkscreen, so the other SPI pins (2=CS*, 4=SDI, 6=GND, 8=SCK) can be identified. As mentioned in the code, exact pinout for the SPI header may change between board revisions, so consult the RPi documentation for details.

    One other detail - RPi ships with SPI kernel drivers disabled by default. Make sure you enable it by editing /boot/config.txt, or use the raspi-config utility. For one-off SPI usage, sudo dtparam spi=on will work to enable SPI0.


    Derek Payne

  • Hi Derek,

    Thank you so much for your suggestion! Please give me 1-2 days for testing to see if it works. Meanwhile, since you mentioned that there is no official support for Raspberry Pi:

    We don't have any official support for Raspberry Pi

    I would like to further ask if there is official support for other small devices like Arduino or such that can be used to program the LMK04832EVM via SPI?


    Yu Jie

  • official support for other small devices like Arduino or such that can be used to program the LMK04832EVM via SPI?

    Not at this time, no. But it's been a very common request over the last two years (likely because of supply chain issues) so we're working on a longer-term solution. We have some ideas how to improve the number of available interfaces for TICS Pro, including both existing interface abstractions like FTDI which come pre-programmed and provide their own driver, and custom interface devices like Arduino as long as the developer is willing to write firmware and drivers which target TICS Pro's register transaction API. Programming support for arbitrary microcontrollers post-evaluation isn't a scalable problem we can solve, since there's no clear hardware abstraction to target across multiple vendors or product families within a vendor's catalog - so that responsibility ultimately must fall to the end user. But we do see scalable advantages to providing post-evaluation linux kernel drivers, since they can be easily re-used in higher-level embedded environments. So linux systems may have an easier time modifying register settings at runtime. Finally, we can improve register and programming documentation to help logically structure configuration design or runtime configuration updates - add flowcharts for configuration of system-level blocks, for example.

    I realize I buried the answer to your question in some other context, so let me restate clearly: I don't foresee us supporting Arduinos, RPi Pico, PIC, or other "simple" microcontrollers directly as part of the TICS Pro evaluation chain, and I don't foresee us adding post-evaluation programming support (e.g. arduino sketches) as this doesn't scale well across the dozens of potential programming toolchains.

  • Hi Derek,

    Thank you for the information. I have tried with your code example given but unfortunately, I am still unable to write to the registers using the raspberry pi. I will be trying with Arduino instead. Nevertheless, thank you for providing support.

    Moving forward, it would be great if you can provide me with a C code for programming the LMK using the Arduino. Very sorry for the trouble.

    Best Regards,

    Yu Jie