What is wrong with this i2c code?

#include <Wire.h>

void setup()
{
  pinMode(13, OUTPUT);
  Wire.begin();
  digitalWrite(13, HIGH);
  Wire.beginTransmission(B1101111);
    Wire.send(0x80); //ctrl reg.
    Wire.send(0x10); //mode1 reg.
    Wire.send(0x00); //mode2 reg.
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00); //GRPPWM reg.
    Wire.send(0x00); //GRPFREQ reg.
    Wire.send(0xAA); //ledout0 reg.
    Wire.send(0xAA); //ledout1 reg.
    Wire.send(0xAA); //ledout2 reg.
    Wire.send(0xAA); //ledout3 reg.
    Wire.send(0xD2); //SUBADR1 reg.
    Wire.send(0xD4); //SUBADR2 reg.
    Wire.send(0xD8); //SUBADR3 reg.
    Wire.send(0xD0); //ALLCALLADR reg.
  Wire.endTransmission();
  digitalWrite(13, LOW);
}


void setLedRegPWM(int address, int ledReg, int PWMVal) {
  Wire.beginTransmission(address);
  Wire.send(ledReg);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(PWMVal);
  Wire.endTransmission(); 
}

void loop()
{
  digitalWrite(13, HIGH);
  setLedRegPWM(0x60, 0x02, 0xFF);
  setLedRegPWM(0x60, 0x03, 0xFF);
  setLedRegPWM(0x60, 0x04, 0xFF);
  setLedRegPWM(0x60, 0x05, 0xFF);
  setLedRegPWM(0x60, 0x06, 0xFF);
  setLedRegPWM(0x60, 0x07, 0xFF);
  setLedRegPWM(0x60, 0x08, 0xFF);
  setLedRegPWM(0x60, 0x09, 0xFF);
  setLedRegPWM(0x60, 0x0A, 0xFF);
  setLedRegPWM(0x60, 0x0B, 0xFF);
  setLedRegPWM(0x60, 0x0C, 0xFF);
  setLedRegPWM(0x60, 0x0D, 0xFF);
  setLedRegPWM(0x60, 0x0E, 0xFF);
  setLedRegPWM(0x60, 0x0F, 0xFF);
  setLedRegPWM(0x60, 0x10, 0xFF);
  setLedRegPWM(0x60, 0x11, 0xFF);
  delay(1000);
  digitalWrite(13, LOW);
  setLedRegPWM(0x60, 0x02, 0x00);
  setLedRegPWM(0x60, 0x03, 0x00);
  setLedRegPWM(0x60, 0x04, 0x00);
  setLedRegPWM(0x60, 0x05, 0x00);
  setLedRegPWM(0x60, 0x06, 0x00);
  setLedRegPWM(0x60, 0x07, 0x00);
  setLedRegPWM(0x60, 0x08, 0x00);
  setLedRegPWM(0x60, 0x09, 0x00);
  setLedRegPWM(0x60, 0x0A, 0x00);
  setLedRegPWM(0x60, 0x0B, 0x00);
  setLedRegPWM(0x60, 0x0C, 0x00);
  setLedRegPWM(0x60, 0x0D, 0x00);
  setLedRegPWM(0x60, 0x0E, 0x00);
  setLedRegPWM(0x60, 0x0F, 0x00);
  setLedRegPWM(0x60, 0x10, 0x00);
  setLedRegPWM(0x60, 0x11, 0x00);
}

When arduino runs it, it just hangs. (led 13 does not turn off...)
I think its not sending the i2c commands.

Thanks in advance.

Wire.send() will hang, when the i2c slave doesn't acknowledge a received frame.

The first question when problems with i2c occur is always: does your circuit have 2.0 kOhm pull-up resistors to 5V for SCL and SDA (values between 1.5 and 2.0kOhm are ok)?

You should strip down your sketch to isolate the problem: does it hang in setup() or in loop()? The "Wire.send()" sequence in setup() looks a bit long, you might have to split it in multiple write calls (e.g. 16 bytes each).

MikeT

I read somewhere that wire lib enables internal pullups, anyway i used a 10k and 4.7k pullups.

#include <Wire.h>

void setup()
{
  setUp(60);
  Wire.begin();
}

void setUp(int address) {
  //Quitar Low-power mode
  Wire.beginTransmission(address);
  Wire.send(0x00);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(0x08); //00001000
  Wire.endTransmission();
  //Modo leds (pwm = AA)
  Wire.beginTransmission(address);
  Wire.send(0x14);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(0xAA); //10101010
  Wire.endTransmission(); 
  Wire.beginTransmission(address);
  Wire.send(0x15);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(0xAA); //10101010
  Wire.endTransmission(); 
  Wire.beginTransmission(address);
  Wire.send(0x16);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(0xAA); //10101010
  Wire.endTransmission(); 
  Wire.beginTransmission(address);
  Wire.send(0x17);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(0xAA); //10101010
  Wire.endTransmission(); 
}

void setLedRegPWM(int address, int ledReg, int PWMVal) {
  Wire.beginTransmission(address);
  Wire.send(ledReg);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.send(PWMVal);
  Wire.endTransmission(); 
}

void loop()
{
  setLedRegPWM(60, 0x02, 0xFF);
  setLedRegPWM(60, 0x03, 0xFF);
  setLedRegPWM(60, 0x04, 0xFF);
  setLedRegPWM(60, 0x05, 0xFF);
  setLedRegPWM(60, 0x06, 0xFF);
  setLedRegPWM(60, 0x07, 0xFF);
  setLedRegPWM(60, 0x08, 0xFF);
  setLedRegPWM(60, 0x09, 0xFF);
  setLedRegPWM(60, 0x0A, 0xFF);
  setLedRegPWM(60, 0x0B, 0xFF);
  setLedRegPWM(60, 0x0C, 0xFF);
  setLedRegPWM(60, 0x0D, 0xFF);
  setLedRegPWM(60, 0x0E, 0xFF);
  setLedRegPWM(60, 0x0F, 0xFF);
  setLedRegPWM(60, 0x10, 0xFF);
  setLedRegPWM(60, 0x11, 0xFF);
  delay(1000);
  setLedRegPWM(60, 0x02, 0x00);
  setLedRegPWM(60, 0x03, 0x00);
  setLedRegPWM(60, 0x04, 0x00);
  setLedRegPWM(60, 0x05, 0x00);
  setLedRegPWM(60, 0x06, 0x00);
  setLedRegPWM(60, 0x07, 0x00);
  setLedRegPWM(60, 0x08, 0x00);
  setLedRegPWM(60, 0x09, 0x00);
  setLedRegPWM(60, 0x0A, 0x00);
  setLedRegPWM(60, 0x0B, 0x00);
  setLedRegPWM(60, 0x0C, 0x00);
  setLedRegPWM(60, 0x0D, 0x00);
  setLedRegPWM(60, 0x0E, 0x00);
  setLedRegPWM(60, 0x0F, 0x00);
  setLedRegPWM(60, 0x10, 0x00);
  setLedRegPWM(60, 0x11, 0x00);
}

The wire.send sequence has to be it this way, the IC has autoincrement. (anyway i can disable it.)
the other device is a TLC69116 by TI.

Thanks.

(Yes, I changed the code, trying to resolve the problem)

edit: oh crap, this is not the latest code... i think i did not save it :cry:
damn it.... i will rewrite the code and reupload it here soon T.T

#include <Wire.h>

void setup()
{
  pinMode(13, OUTPUT);
  Wire.begin();
  Wire.beginTransmission(B1101111);
    Wire.send(0x80); //ctrl reg.
    Wire.send(0x10); //mode1 reg.
    Wire.send(0x00); //mode2 reg.
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00); //GRPPWM reg.
    Wire.send(0x00); //GRPFREQ reg.
    Wire.send(0xAA); //ledout0 reg.
    Wire.send(0xAA); //ledout1 reg.
    Wire.send(0xAA); //ledout2 reg.
    Wire.send(0xAA); //ledout3 reg.
    Wire.send(0xD2); //SUBADR1 reg.
    Wire.send(0xD4); //SUBADR2 reg.
    Wire.send(0xD8); //SUBADR3 reg.
    Wire.send(0xD0); //ALLCALLADR reg.
  Wire.endTransmission();
  digitalWrite(13, HIGH);
}


void setLedRegPWM(int address, int ledReg, int PWMVal) {
  Wire.beginTransmission(address);
  Wire.send(ledReg);
  Wire.send(PWMVal);
  Wire.endTransmission();
}

void loop()
{
  digitalWrite(13, HIGH);
  setLedRegPWM(0x60, 0x02, 0xFF);
  setLedRegPWM(0x60, 0x03, 0xFF);
  setLedRegPWM(0x60, 0x04, 0xFF);
  setLedRegPWM(0x60, 0x05, 0xFF);
  setLedRegPWM(0x60, 0x06, 0xFF);
  setLedRegPWM(0x60, 0x07, 0xFF);
  setLedRegPWM(0x60, 0x08, 0xFF);
  setLedRegPWM(0x60, 0x09, 0xFF);
  setLedRegPWM(0x60, 0x0A, 0xFF);
  setLedRegPWM(0x60, 0x0B, 0xFF);
  setLedRegPWM(0x60, 0x0C, 0xFF);
  setLedRegPWM(0x60, 0x0D, 0xFF);
  setLedRegPWM(0x60, 0x0E, 0xFF);
  setLedRegPWM(0x60, 0x0F, 0xFF);
  setLedRegPWM(0x60, 0x10, 0xFF);
  setLedRegPWM(0x60, 0x11, 0xFF);
  delay(1000);
  digitalWrite(13, LOW);
  setLedRegPWM(0x60, 0x02, 0x00);
  setLedRegPWM(0x60, 0x03, 0x00);
  setLedRegPWM(0x60, 0x04, 0x00);
  setLedRegPWM(0x60, 0x05, 0x00);
  setLedRegPWM(0x60, 0x06, 0x00);
  setLedRegPWM(0x60, 0x07, 0x00);
  setLedRegPWM(0x60, 0x08, 0x00);
  setLedRegPWM(0x60, 0x09, 0x00);
  setLedRegPWM(0x60, 0x0A, 0x00);
  setLedRegPWM(0x60, 0x0B, 0x00);
  setLedRegPWM(0x60, 0x0C, 0x00);
  setLedRegPWM(0x60, 0x0D, 0x00);
  setLedRegPWM(0x60, 0x0E, 0x00);
  setLedRegPWM(0x60, 0x0F, 0x00);
  setLedRegPWM(0x60, 0x10, 0x00);
  setLedRegPWM(0x60, 0x11, 0x00);
  delay(1000);
}

This should be correct.
I used 4.7k pullups from 5V to A4 and A5.

I couldn't find a datasheet for the TLC69116 but there is a TLC59116 i2c LED driver, do you mean that one?

Your setup() function is wrong:

  1. The order of Wire.begin() and setUp() must be exchanged
  2. The i2c address of the TLC59116 is B0110xxxx with xxxx=A3,A2,A1,A0. Assuming A0 to A3=0, then the address would be 0x60 hex, but it can never be 60 decimal which would be 0x3C

Try it with this version:

void setup()
{
  Wire.begin();
  setUp(0x60);
}

How did you connect the A0 to A3 address pins? You have to adapt the 0x60 accordingly.

In your first post and latest you were using the addresses 0x60 and B01101111=0x6F. Did you want to use the ALLCALLADR B01101000=0x68 instead? One of the two addresses is wrong.

Can you strip down the code so it only reads / writes a single byte from your device to make sure it works at all?

MikeT

Yes, the numbers on the IC are very small haha. It's a TLC59116F.
All the address pins are directly conected to ground, so the address should be 0x60.
I dont understand the last qustion.
Btw, the led attached to pin 13 its now blinking. I have adapted the code.
Anyway the leds attached to TLC don't blink, so i think the only wron thing in my code now is the way i tur on and off all the leds, as lon as the autoincrease register is activated, i have to do it that way.

Sorry my english :-/

have you changed the address in the setup function? I also think the SLEEP mode should be disabled and GRPPWM=0xff:

void setup()
{
  pinMode(13, OUTPUT);
  Wire.begin();
  //Wire.beginTransmission(B1101111); // wrong address
  Wire.beginTransmission(B1100000); // corrected address
    //Wire.send(0x10); //mode1 reg. SLEEP mode ON
    Wire.send(0x00); //mode1 reg. SLEEP mode OFF
    Wire.send(0x00); //mode2 reg.

    Wire.send(0x00); // PWM0
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00);
    Wire.send(0x00); // PWM15

    //Wire.send(0x00); //GRPPWM reg.
    Wire.send(0xFF); //GRPPWM reg.
    Wire.send(0x00); //GRPFREQ reg.
    Wire.send(0xAA); //ledout0 reg.
    Wire.send(0xAA); //ledout1 reg.
    Wire.send(0xAA); //ledout2 reg.
    Wire.send(0xAA); //ledout3 reg.
    Wire.send(0xD2); //SUBADR1 reg.
    Wire.send(0xD4); //SUBADR2 reg.
    Wire.send(0xD8); //SUBADR3 reg.
    Wire.send(0xD0); //ALLCALLADR reg.
  Wire.endTransmission();
  digitalWrite(13, HIGH);
}

MikeT

I solved it, its the tipycal "minor" fail.
I put an 1 where there should be a 0 to remove the (default-power-on) sleep mode of the IC.

Thanks for the fast help anyway :slight_smile:

Oh and as i was expecting, you will resolve it at the same time as me haha.
Yes, is that. Thanks a lot.