I2C questions with TLC59116 *solved, now with code example*

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

I2C questions with TLC59116 *solved, now with code example*

Post by hyperion007 »

Hi,

I have never used anything requiring I2C but I have searched the entire forum as well as the Ti forums without any luck

I cannot seem to get this LED driver to work. I have set the hardware I2C address pins to GND so the address should be 1100000 (first three bits are fixed and the last four are hardware coded to GND)

in the datasheet it says that the address is 7-bit followed by R/W which should be 0 for write.

Should I then transmit byte 0xC0? or 0x60? (1100 0000 or 1100 000) What about the R/W bit?

Also, does the I2C function in FC send LSB or MSB? The TLC59116 needs it to be MSB, but when I look at the I2C component in the FC panel it says that it is sending LSB (I think)

I have tried using both LSB and MSB format, sending 0b10000000 and 0b00000001 for example. But still can't get this to work.

I'll attach the datasheet and maybe some kind soul can put together a small FCF file to turn on one or two LEDs. After that I can probably figure it out :)

I am using a PIC18F2520


Edit: File to big :( again. so here is the link to the datasheet:

http://www.ti.com/lit/ds/slds157d/slds157d.pdf
Last edited by hyperion007 on Fri May 10, 2013 10:03 am, edited 1 time in total.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: I2C questions with TLC59116

Post by LeighM »

Page 25 gives the best help on how to communicate with the device.
MSB is sent first.
To write to a register, the sequence is…

MasterI2C_Start
Ack = MasterI2C_Transmit_Byte(0xC0) // address of slave device, bit 0 = 0 for write
if (Ack =0)
{
Ack = MasterI2C_Transmit_Byte(address of register to write)
If (Ack =0)
{
Ack = MasterI2C_Transmit_Byte(data)
}
}
MasterI2C_Stop

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

Thanks!

Do I need to do some sort of wait until I get the ACK?

For example:
MasterI2C_Start
Ack = MasterI2C_Transmit_Byte(0xC0) // address of slave device, bit 0 = 0 for write
connection point A:A
if (Ack =0)
{
Ack = MasterI2C_Transmit_Byte(address of register to write)
Else go to A:A

I thought that the ACK should be =1?

It says: "The acknowledge bit is a high level put on the bus by the transmitter, whereas the master generates an extra acknowledge related clock pulse."

Should I change your example to "if (ACK=1)" instead?


If I send 0xC0 which is 0b1100 000 I see in the window of the I2C component in the panel that it says that it has sent "3" which would indicate that it has sent 0000 0011 ? I might be wrong, I will find out tonight :)

I will try this when I get home.

Thanks again.

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

I just want to verify that the I2C component in FC does this:

"The device that acknowledges has to pull down the SDA line during the acknowledge clock pulse, so
that the SDA line is stable low during the high period of the acknowledge related clock pulse; setup time and hold
time must be taken into account.

A master receiver must signal an end of data to the transmitter by not generating an acknowledge on the last
byte that has been clocked out of the slave. In this event, the transmitter must leave the data line high to enable
the master to generate a Stop condition."

I don't know what the I2C standard says so I don't know if this is part of that standard or can be different from one component to the next

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C questions with TLC59116

Post by Benj »

Hello,

Yes Flowcode takes care of the I2C bus correctly and the ack's. You do not have to poll for the ack it should be there immediately when you call the component macro.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: I2C questions with TLC59116

Post by LeighM »

Hi
It is easy to get confused as to what the master and slave are doing.
The data sheet is misleading you a little. When writing, the master outputs a high, but the slave changes this to a low to signal an Ack.
The sequence is different when the master is reading from the slave.
Try the code as it is. You just need the few calls to the Flowcode macros and test the Ack returns.
As Ben says, the Flowcode macros take care of the line signalling for you.
Regards,
Leigh

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

Ok thanks guys! I will let you guys know how I fare with it in about 2 hours :)
Looking at the datasheet again, on page 25, I thing I know what I did wrong. I had set the auto increment bits to 000 and tried to send new register byte and corresponding data then new register byte and corresponding data. But without auto increment enabled I think I need to write the control byte with auto increment off and register bits followed by the data to that register and then stop.

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

YES! That did the trick :)

Thanks guys! Now I'm off work until Monday and can concentrate on programming :)

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: I2C questions with TLC59116

Post by dazz »

Hi
Can you post a basic working flowchart for that chip as it will help someone else who is struggling

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

Sure, no problem. Just have to clean it up a bit :)

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

Here is the flowcode file and a small video showing what it will/should look like.

Remember that the TLC59116 can only sink so if you want to use RGB LEDs, choose the correct ones.

Video: http://youtu.be/hwIgcCBhLxk
Attachments
LED Driver i2c TLC59116.fcf
(21.18 KiB) Downloaded 509 times

hyperion007
Posts: 528
Joined: Sat Dec 01, 2012 1:23 pm
Location: Sweden
Has thanked: 49 times
Been thanked: 101 times
Contact:

Re: I2C questions with TLC59116

Post by hyperion007 »

Another video, now with a LED bargraph.

http://youtu.be/Nhh_WCOroQc

Post Reply