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.

LP5562: LP5562

Part Number: LP5562

Hi,

I am using an LP5562 LED driver in my device. Now I am facing two issues when I try to Load the LED pattern into the SRAM of LP5562.

1) Sometimes Writing to Engine #1(10H) fails((1 out of 10 times)

2) Sometimes All I2C operations are successful but the pattern is not as expected(1 out of 25 times). I have added a workaround here that Writing to Enginee #1 fails to try again.

I am attaching my code snippet for the same let me know if I am doing something unexpected with I2C operations. 

// @brief LP5562 Register Map

typedef enum
{
    LP5562_REG_ENABLE           = 0x00,
    LP5562_REG_OP_MODE          = 0x01,
    LP5562_REG_B_PWM            = 0x02,
    LP5562_REG_G_PWM            = 0x03,
    LP5562_REG_R_PWM            = 0x04,
    LP5562_REG_B_CURRENT        = 0x05,
    LP5562_REG_G_CURRENT        = 0x06,
    LP5562_REG_R_CURRENT        = 0x07,
    LP5562_REG_CONFIG           = 0x08,
    LP5562_ENG1_PC              = 0x09,
    LP5562_ENG2_PC              = 0x0A,
    LP5562_ENG3_PC              = 0x0B,
    LP5562_STATUS_INT           = 0x0C,     // Read Only
    LP5562_REG_RESET            = 0x0D,
    LP5562_REG_W_PWM            = 0x0E,
    LP5562_REG_W_CURRENT        = 0x0F,
    LP5562_REG_ENG_SEL          = 0x70,
    LP5562_REG_PROG_MEM_ENG1    = 0x10,
    LP5562_REG_PROG_MEM_ENG2    = 0x30,
    LP5562_REG_PROG_MEM_ENG3    = 0x50,
} lp5562_register_t;

//
//  LED LP5562 Defines
//
#define LED_LP5562_ENGINE_RAM_SIZE      (16)
#define LED_LP5562_CURRENT_ARRAY_SIZE   (3)
// Enable Register Configurations
#define LP5562_MASTER_ENABLE        				( 0x40 )	// Chip master enable
#define LP5562_LOGARITHMIC_PWM      				( 0x80 )
#define LP5562_EXEC_RUN             				( 0x2A )
#define LP5562_ENABLE_RUN_PROGRAM   				( 0x6A )
#define LP5562_ENABLE_DEFAULT       				( LP5562_MASTER_ENABLE | LP5562_LOGARITHMIC_PWM )
#define LP5562_RESET_ENABLE         				( 0x00 )

// Opmode Register
#define LP5562_MODE_ENG1_M          				( 0x30 )
#define LP5562_MODE_ENG2_M          				( 0x0C )
#define LP5562_MODE_ENG3_M          				( 0x03 )
#define LP5562_LOAD_ENG1            				( 0x10 )
#define LP5562_LOAD_ENG2            				( 0x04 )
#define LP5562_LOAD_ENG3            				( 0x01 )
#define LP5562_RUN_ENG1             				( 0x20 )
#define LP5562_RUN_ENG2             				( 0x08 )
#define LP5562_RUN_ENG3             				( 0x02 )
#define LP5562_ENG_SET_LOAD         				( 0x15 )
#define LP5562_ENG_SET_DISABLE      				( 0x00 )
#define LP5562_ENG_SET_RUN          				( 0x2A )
#define LP5562_ENG_SET_DIRECT       				( 0xFF )


typedef struct __attribute__((__packed__))
{
    uint8_t     bEngine1LED;
    uint16_t    awEngine1[ LED_LP5562_ENGINE_RAM_SIZE ];
    uint8_t     bEngine2LED;
    uint16_t    awEngine2[ LED_LP5562_ENGINE_RAM_SIZE ];
    uint8_t     bEngine3LED;
    uint16_t    awEngine3[ LED_LP5562_ENGINE_RAM_SIZE ];
    uint8_t     abCurrentControl[ LED_LP5562_CURRENT_ARRAY_SIZE ];
} tLEDPattern;

		//Enable LP5562 LED Driver chip.
		ulRegValue = LP5562_MASTER_ENABLE ;
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_ENABLE , (uint8_t *)&ulRegValue , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		// Put 600us Delay.
		vNU_DelayInUs( DELAY_600_US );

		//Use Internal Clock.
		ulRegValue = APP_LP5562_CFG_REG_VALUE ;
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_CONFIG , (uint8_t *)&ulRegValue , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );
		
		//Map ENG1-R ENG2-G ENG3-B I2C-W
		ulRegValue = ulAPP_GetLEDMapping ( ptLEDPacket, &ulRegOpModeVal, &ulRegEnableVal ) ;
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_ENG_SEL , (uint8_t *)&ulRegValue , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		//Configure ENG1,ENG2,ENG3 into 'Load program to SRAM' mode.
		ulRegValue = LP5562_ENG_SET_LOAD;
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_OP_MODE , (uint8_t *)&ulRegValue , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		if( ptLEDPacket -> bEngine1LED )
		{
			//Load program to ENG1 SRAM(10H).
			tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_PROG_MEM_ENG1 , (uint8_t *)ptLEDPacket->awEngine1 , LP5562_PATTERN_SIZE );
			NU_BREAK_ON_FAILURE( tI2CStatus );
		}

		tError =  eLayer2Error;
		if( ptLEDPacket -> bEngine2LED )
		{
			//Load program to ENG2 SRAM(30H).
			tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_PROG_MEM_ENG2 , (uint8_t *)ptLEDPacket->awEngine2  , LP5562_PATTERN_SIZE );
			NU_BREAK_ON_FAILURE( tI2CStatus );
		}

		tError =  eLayer3Error;
		if( ptLEDPacket -> bEngine3LED )
		{
			//Load program to ENG3 SRAM(50H).
			tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_PROG_MEM_ENG3 , (uint8_t *)ptLEDPacket->awEngine3  , LP5562_PATTERN_SIZE );
			NU_BREAK_ON_FAILURE( tI2CStatus );
		}

		tError =  eCurrentArrayError;
		//set Current Values
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_B_CURRENT , ptLEDPacket->abCurrentControl, LP5562_NUM_LEDS );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		//Disable all Engines.
		ulRegValue = DISABLE_ALL_ENG;
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_OP_MODE , (uint8_t *)&ulRegValue , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		//Run Program .
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_OP_MODE , (uint8_t *)&ulRegOpModeVal , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		//Chip enable & Run all ENG.
		tI2CStatus = tHAL_I2CM_WriteRegister( I2CM_LP5562_LED_DRIVER , LP5562_REG_ENABLE , (uint8_t *)&ulRegEnableVal , NU_I2C_SINGLE_BYTE );
		NU_BREAK_ON_FAILURE( tI2CStatus );

		tError =  eNoError;
		// Put 600us Delay.
		vNU_DelayInUs( DELAY_600_US );