Cannot make IS31FL3193 work with nRF52840

Hi,

I am struggling with making the IS31FL3193 LED controller work with nRF52840 on a custom board.

I tried to just send some write functions based on the chip documentation, however no result.

I've found a sample code for Arduino from the chip provider, so I remade it for nRF MCU, but also no results.

The problem with this chip is that you can only write to registers, so I have no option to read and verify if the connection works.

But when I run a simple I2C scanner I can see the addresses.

here is my code

// 0x00, 0x20 // Normal operation
// 0x02, 0x20 // One shot programming mode
// 0x03, 0x00 // Imax=42mA
// 0x04, 0xFF // PWM
// 0x05, 0xFF // PWM
// 0x06, 0xFF // PWM
// 0x07, 0x00 // Update
// 0x0A, 0x00 // OUT1 T0=0
// 0x0B, 0x10 // OUT2 T0=0.13s
// 0x0C, 0x20 // OUT3 T0=0.26s
// 0x10, 0x46 // OUT1 T1=1.04S
// 0x11, 0x46 // OUT2 T1=1.04S
// 0x12, 0x46 // OUT3 T1=1.04S
// 0x16, 0x46 // OUT1 T3=1.04S
// 0x17, 0x46 // OUT2 T3=1.04S
// 0x18, 0x46 // OUT3 T3=1.04S
// 0x1D, 0x07 // Turn on LED
// 0x1C, 0x00 // Update

#include <zephyr/kernel.h>
#include <drivers/include/nrfx_twim.h>

#include "SEGGER_RTT.h"
#include "SEGGER_RTT_printf.c"

#include <zephyr/drivers/gpio.h>

const struct device *gpio0 = DEVICE_DT_GET(DT_NODELABEL(gpio0));

const nrfx_twim_t twim = NRFX_TWIM_INSTANCE(0);

const nrfx_twim_config_t twim_config = {
    .scl_pin                = 6,
    .sda_pin                = 4,
    .frequency          = NRF_TWIM_FREQ_400K,  // 400kHz I2C frequency
	.interrupt_priority = NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY,
    .hold_bus_uninit    = false
};

void IS_IIC_WriteByte(uint8_t reg_addr, uint8_t reg_dat) {
    uint8_t data[] = {reg_addr, reg_dat};
    nrfx_twim_xfer_desc_t xfer = NRFX_TWIM_XFER_DESC_TX(0xD0 >> 1, data, sizeof(data));
    nrfx_err_t err_val = (&twim, &xfer, 0);

    if (err_val == NRFX_SUCCESS)
    {
        SEGGER_RTT_printf(0, "SUCCESS");
    }
    else
    {
        SEGGER_RTT_printf(0, "ERROR");
    }
}

void IS31FL3193_Breath_mode()
{
    IS_IIC_WriteByte(0x00, 0x20); // Normal operation
    IS_IIC_WriteByte(0x02, 0x20); // One shot programming mode
    IS_IIC_WriteByte(0x03, 0x00); // Imax=42mA
    IS_IIC_WriteByte(0x04, 0xFF); // PWM
    IS_IIC_WriteByte(0x05, 0xFF); // PWM
    IS_IIC_WriteByte(0x06, 0xFF); // PWM
    IS_IIC_WriteByte(0x07, 0x00); // Update
    IS_IIC_WriteByte(0x0A, 0x00); // OUT1 T0=0
    IS_IIC_WriteByte(0x0B, 0x10); // OUT2 T0=0.13s
    IS_IIC_WriteByte(0x0C, 0x20); // OUT3 T0=0.26s
    IS_IIC_WriteByte(0x10, 0x46); // OUT1 T1=1.04S
    IS_IIC_WriteByte(0x11, 0x46); // OUT2 T1=1.04S
    IS_IIC_WriteByte(0x12, 0x46); // OUT3 T1=1.04S
    IS_IIC_WriteByte(0x16, 0x46); // OUT1 T3=1.04S
    IS_IIC_WriteByte(0x17, 0x46); // OUT2 T3=1.04S
    IS_IIC_WriteByte(0x18, 0x46); // OUT3 T3=1.04S
    IS_IIC_WriteByte(0x1D, 0x07); // Turn on LED
    IS_IIC_WriteByte(0x1C, 0x00); // Update
}

int main(void)
{
    int ret = gpio_pin_configure(gpio0, 27, GPIO_OUTPUT_ACTIVE | GPIO_PULL_DOWN); // FLAGS should be replaced with additional configuration flags as needed, like GPIO_PULL_UP if you're using a pull-up resistor.
    if (ret != 0) {
        printk("Error %d: Failed to configure GPIO pin\n", ret);
        return;
    }

    nrfx_twim_init(&twim, &twim_config, NULL, NULL);
    nrfx_twim_enable(&twim);

    gpio_pin_set(gpio0, 27, 1);
    
    IS31FL3193_Breath_mode();

    while(1)
    {
        k_sleep(K_SECONDS(1));
    }

    nrfx_twim_disable(&twim);

    return;
}

and here is a snippet from device tree

&pinctrl 
{
i2c0_default: i2c0_default
    {
        group1
        {
            psels = <NRF_PSEL(TWIM_SDA, 0, 4)>,
                    <NRF_PSEL(TWIM_SCL, 0, 6)>;
        };
    };

    i2c0_sleep: i2c0_sleep
    {
        group1
        {
            psels = <NRF_PSEL(TWIM_SDA, 0, 4)>,
                    <NRF_PSEL(TWIM_SCL, 0, 6)>;
            low-power-enable;
        };
    };
};

&i2c0 
{
	compatible = "nordic,nrf-twim";
    status = "okay";
	pinctrl-0 = <&i2c0_default>;
	pinctrl-1 = <&i2c0_sleep>;
	pinctrl-names = "default", "sleep";
};

here I also tried different options, but all of them gave nothing.

I will be thankful for any help or suggestions, as there are no examples or codes online to use this controller.

Parents Reply Children
No Data
Related