On my last post I had barely scratched the surface of what the LP55231 could do and was reading about the three program execution engines. After a bit of research I found that TI supplies a dashboard program and an assembler for the chip, but only for their own LP55231SQEVM evaluation board.

The assembler may work without the EVM, but both programs are windows-only anyway. That means I've instantly lost interest, as I'm a Linux guy. The dashboard runs with Wine, but I don't have their board, so that's a moot point. I didn't even try to get the assembler to work. Chances are fairly good that it would work with Wine, but I don't care to work that hard. Anyways, LP55231 programs can only be 96 instructions at most, so hand assembling is pretty simple.

I don't care for using other people's driver libraries to control things. You don't learn anything that way. But I'm certainly not above having a look at their driver source if I get stuck. I did have a look at Sparkfun's code this time, but didn't learn anything except that I had made a typo setting one register. Fixed that bug and then it worked.

Now that I can program the chip and load Sparkfun's demo program onto it I think I'll write a few of my own. What fun!

Here's a MicroPython demo of writing a program to the chip. The program I'm writing is Sparkfun's example with changes to mapping to suit my setup:

# ghmicro.com
# LP55231 LED driver - hardware I2c

import time
from machine import I2C, Pin

i2c = machine.I2C(1,freq=400000)

progpage1 = [0x9c,0x10, #00 map start
            0x9c,0x9f,  #01 map end
            0x06,0xff,  #02 ramp up
            0x02,0x00,  #03 wait
            0x07,0xff,  #04 ramp down
            0x9d,0x80,  #05 map next
            0xa0,0x02,  #06 loop to 2
            0x00,0x0a,  #07 - empty placeholder
            0x00,0x05,  #08 - empty placeholder
            0x00,0x0a,  #09 - empty placeholder
            0x00,0x05,  #0a - empty placeholder
            0x00,0x0a,  #0b - empty placeholder
            0x00,0x05,  #0c - empty placeholder
            0x00,0x0a,  #0d - empty placeholder
            0x00,0x05,  #0e - empty placeholder
            0x00,0x0a]  #0f - empty placeholder
progpage2 = [0x00,0x02, #10 map begin - start of 2nd page
            0x00,0x01,  #11
            0x00,0x40,  #12
            0x00,0x08,  #13
            0x00,0x04,  #14
            0x00,0x80,  #15
            0x00,0x20,  #16
            0x00,0x10,  #17
            0x01,0x00,  #18
            0x00,0x10,  #19
            0x00,0x20,  #1a
            0x00,0x80,  #1b
            0x00,0x04,  #1c
            0x00,0x08,  #1d
            0x00,0x40,  #1e
            0x00,0x01]  #1f map end
progarray1 = bytearray(progpage1)
progarray2 = bytearray(progpage2)
byt = bytearray(2)

def writepair(address,value):
    byt[0] = address
    byt[1] = value
    i2c.writeto(0x32,byt)

writepair(0x00,0x40)        #enable lp55231
pyb.delay(10)               #wait to enter normal mode
writepair(0x36,0x7f)        #powersave on, auto charge pump, internal clock, auto increment
writepair(0x01,0x00)        #set all engines to disabled
writepair(0x01,0x10)        #set engine 1 to load mode
pyb.delay(1)                #wait 1ms for initialization

writepair(0x4f,0x00)        #select memory page 0
i2c.writeto_mem(0x32,0x50,progarray1) #write program to memory
writepair(0x4f,0x01)        #select memory page 1
i2c.writeto_mem(0x32,0x50,progarray2) #write program to memory

writepair(0x01,0x20)        #set engine 1 to run mode
writepair(0x00,0x60)        #set prog exec from hold to run

Next Post Previous Post