LP55231: Not able to read and write the program memory of SRAM of LP55231

Part Number: LP55231
Other Parts Discussed in Thread: LP5813

Tool/software:

I have using the Raspberrypi 3 B+ with LP55231 via i2c, i able to write the register to glow the LED connected to D7 and D9 using python and attaching the python code.

So, the goal is to glow the D7 and D9 on powerOn state.

import smbus2
import time
import RPi.GPIO as GPIO

# I2C bus (1 for Raspberry Pi 3)
bus = smbus2.SMBus(1)
# LP55231 I2C address
address = 0x32
# GPIO pin for ENABLE (BCM numbering)
ENABLE_PIN = 17

def setup_gpio():
    """Setup the GPIO pin for ENABLE and set it HIGH to enable the LP55231."""
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(ENABLE_PIN, GPIO.OUT)
    GPIO.output(ENABLE_PIN, GPIO.HIGH)  # Enable the LP55231

def read_register(register):
    """Read a byte from the specified register over I2C."""
    value = bus.read_byte_data(address, register)
    print(f"Read value {value:#04x} from reg {register:#04x}")
    return value

def write_register(register, value):
    """Write a byte to the specified register over I2C."""
    bus.write_byte_data(address, register, value)
#    print(f"Wrote value {value:#04x} to register {register:#04x}")
    read_register(register)

def init_lp55231():
    """Initialize the LP55231 LED driver."""
    # Reset device
    write_register(0x00, 0x40)
    write_register(0x01, 0x15)
#    write_register(0x05, 0x40)

    time.sleep(0.1)

    # Enable all engines and set up for internal clock and power on state
    write_register(0x36, 0x0F)  # Engine 1 control
#   write_register(0x37, 0x0F)  # Engine 2 control
#   write_register(0x38, 0x0F)  # Engine 3 control

    # Set LED current (assuming you want full current, adjust as necessary)
    write_register(0x26, 0x32)  # Red LED current (50% max)
    write_register(0x27, 0x32)  # Green LED current (50% max)
    write_register(0x28, 0x32)  # Blue LED current (50% max)

    # Enable output control for all LEDs
    write_register(0x16, 0xFF)
    write_register(0x17, 0xFF)
    write_register(0x18, 0xFF)
    write_register(0x71, 0x40)
    write_register(0x2C, 0xB7)
    write_register(0x0C, 0x80)

    # Load program into SRAM
    enable_auto_boot()
    load_program_to_sram()
   

    # Configure to run program on boot
    # Set auto-increment to keep writing instructions
    write_register(0x3D, 0x01)
    read_register(0x3A)
    # Delay to ensure LP55231 starts executing the program
    time.sleep(0.5)

def load_program_to_sram():
    """Load a program into the SRAM to set the green LED on power up."""
    # Example program to set green LED to max brightness
    program = [
        0x9D, 0x03,  # LDI R6, 100 (max brightness)
        0x40, 0x96,        # MOV R6, PWM1 (move value to green PWM register)
        0xC0, 0x00,        # MOV R6, PWM1 (move value to green PWM register)
        0x01, 0x00,        # NOP (no operation, end of program)
    ]
    sram_address = 0x50  # Program memory starts at 0x50

    # Write program to SRAM
    for i, instruction in enumerate(program):
        write_register(sram_address + i, instruction)
#        read_register(sram_address + i)

def enable_auto_boot():
    """Enable LP55231 to execute the program from SRAM on power-up."""
    # Set engine 1 to execute program from SRAM on boot
    write_register(0x4C, 0x50)  # Set program counter to start of SRAM
    write_register(0x37, 0x00)  # Engine 2 control
#    write_register(0x00, 0x60)  # Start engine 1

def main():
    try:
        setup_gpio()
        init_lp55231()
        read_register(0x50)
        # Remain in a loop or sleep to keep the program running
#        while True:
 #           time.sleep(1)

    finally:
        # Clean up GPIO
        GPIO.cleanup()

if __name__ == "__main__":
    main()


-----------------------------------------------------------------End of program

Read value 0x40 from reg 0x00
Read value 0x15 from reg 0x01
Read value 0x0f from reg 0x36
Read value 0x32 from reg 0x26
Read value 0x32 from reg 0x27
Read value 0x32 from reg 0x28
Read value 0xff from reg 0x16
Read value 0xff from reg 0x17
Read value 0xff from reg 0x18
Read value 0x00 from reg 0x71
Read value 0xb7 from reg 0x2c
Read value 0x80 from reg 0x0c
Read value 0x50 from reg 0x4c
Read value 0x00 from reg 0x37
Read value 0x00 from reg 0x50
Read value 0x00 from reg 0x51
Read value 0x00 from reg 0x52
Read value 0x00 from reg 0x53
Read value 0x00 from reg 0x54
Read value 0x00 from reg 0x55
Read value 0x00 from reg 0x56
Read value 0x00 from reg 0x57
Read value 0x00 from reg 0x3d
Read value 0x50 from reg 0x3a
Read value 0x00 from reg 0x50


---------------------------------------------logs for the above code.

in that i can see the program memory address start from 0x50 can't be write with data

is there any sequence i have missed here, any suggestions kindly provide the same


  • Hi Varu,

    Please give me some time since I am OoO these days, I will reply to you later.

    BR, Jared

  • Hi Jared Zhou,

    Can you help here?

  • Hi Varu,

    Sorry for the late reply.

    My understanding is that you want to use the internal animation in LP55231, but when you program the SRAM in LP55231, it doesn't work. Am I right?

    Please refer the below main steps to program SRAM:

    1. Set the chip_en to enable the device, write 40h to register 00h

    2. Configure engine into "Load program to SRAM" mode, write 15h to register 01h

    3. Then, you can still to configure the DC, PWM and other setting.

    4. Program the SRAM

    5. After you finishing the SRAM in LP55231, please configure the operation mode to "Run program". Write 2Ah to register 01h

    6. Configure program execution mode from HOLD to RUN for the engine. Write 6A to register 00h

    Btw, I think the data in SRAM can't be read back since I can't read back either.

    Last question, can you please tell me why you choose LP55231 as your LED driver? Why I ask this question is because, we have the next-gen LP55231, LP5813 with better performance, supply and support, especially the internal animation. LP5813 is much better than LP55231.

    BR, Jared